-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from nevalang/err_guard
Error guard `?` operator
- Loading branch information
Showing
32 changed files
with
1,986 additions
and
1,584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package test | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
err := os.Chdir("..") | ||
require.NoError(t, err) | ||
|
||
wd, err := os.Getwd() | ||
require.NoError(t, err) | ||
defer os.Chdir(wd) | ||
|
||
cmd := exec.Command("neva", "run", "advanced_error_handling") | ||
out, err := cmd.CombinedOutput() | ||
require.NoError(t, err) | ||
require.Equal( | ||
t, | ||
`panic: {"text": "Get \"definitely%20not%20a%20valid%20URL\": unsupported protocol scheme \"\""} | ||
`, | ||
string(out), | ||
) | ||
|
||
require.Equal(t, 0, cmd.ProcessState.ExitCode()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { http } | ||
|
||
component Main(start) (stop) { | ||
nodes { App, Println, Panic } // Panic will crash the program | ||
net { | ||
:start -> app:sig | ||
app:err -> panic // we only handle err at this lvl | ||
app:data -> println -> :stop | ||
} | ||
} | ||
|
||
component App(sig) (data string, err error) { | ||
nodes { http.Get? } // '?' implicitly sends err downstream | ||
net { | ||
:sig -> ('definitely not a valid URL' -> get) | ||
get:resp.body -> :data // look ma, no error handling! | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { http } | ||
|
||
component Main(start) (stop) { | ||
nodes { http.Get, Println } | ||
net { | ||
:start -> ('http://www.example.com' -> get) | ||
get:resp.body -> println -> :stop | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.