MCPcopy Create free account
hub / github.com/dagger/dagger / TestErrors

Method TestErrors

core/integration/module_python_test.go:2035–2114  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

2033}
2034
2035func (PythonSuite) TestErrors(ctx context.Context, t *testctx.T) {
2036 c := connect(ctx, t)
2037 ctr := goGitBase(t, c).
2038 WithWorkdir("/work/dep").
2039 With(daggerInitPython("--name=dep")).
2040 With(fileContents("src/dep/__init__.py", fmt.Sprintf(`
2041 import dagger
2042 from dagger import dag
2043
2044 @dagger.object_type
2045 class Dep:
2046 @dagger.function
2047 async def exec_(self) -> str:
2048 return await (
2049 dag.container()
2050 .from_("%s")
2051 .with_exec(["sh", "-c", ">&2 echo 'oh noes'; exit 5"])
2052 .stdout()
2053 )
2054 `, alpineImage))).
2055 WithWorkdir("/work/test").
2056 With(daggerInitPython()).
2057 With(daggerExec("install", "../dep")).
2058 With(pythonSource(`
2059 import dagger
2060 from dagger import dag
2061
2062 @dagger.object_type
2063 class Test:
2064 @dagger.function
2065 async def error_extensions(self) -> str:
2066 try:
2067 return await dag.dep().exec()
2068 except dagger.ExecError as e:
2069 # If the SDK didn't properly propagate the error
2070 # extensions this would be a dagger.QueryError instead,
2071 # so not caught.
2072 assert e.exit_code == 5
2073 return f"error: {e.stderr}"
2074
2075 @dagger.function
2076 def coro(self) -> str:
2077 # Should fail because dag.version() returns a coroutine
2078 # and this isn't an async function
2079 return dag.version()
2080
2081 @dagger.function
2082 async def nowait(self) -> str:
2083 # Should fail because of missing await
2084 return dag.version()
2085
2086 @dagger.function
2087 def unhandled(self) -> str:
2088 raise ValueError("a foo bubbles up to bar")
2089 `))
2090
2091 t.Run("error extensions", func(ctx context.Context, t *testctx.T) {
2092 out, err := ctr.With(daggerCall("error-extensions")).Stdout(ctx)

Callers

nothing calls this directly

Calls 15

goGitBaseFunction · 0.85
daggerInitPythonFunction · 0.85
fileContentsFunction · 0.85
daggerExecFunction · 0.85
pythonSourceFunction · 0.85
daggerCallFunction · 0.85
requireErrOutFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
EqualMethod · 0.65
SyncMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected