winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.06k stars 198 forks source link

Distinguish between SDK and user land errors #3507

Open skorfmann opened 1 year ago

skorfmann commented 1 year ago

Feature Spec

It's now easier for users to distinguish between SDK - as in internal Wing - errors and user land errors. Up until now, it was difficult to spot what the source of the error could be.

Take this very generic error message as an example:

     │ Error: Invoke failed with message: "Unhandled". Full error: "{"errorType":"SyntaxError","errorMessage":"Unexpected token u in JSON at position 0","trace":["SyntaxError: Unexpected token u in JSON at position 0","    at JSON.parse (<anonymous>)","    at /var/task/index.js:1725:22","    at exports.handler (/var/task/index.js:1733:5)","    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1086:29)"]}"
     │     at FunctionClient.invoke (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/node_modules/@winglang/sdk/lib/shared-aws/function.inflight.js:21:19)
     │     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     │     at async TestRunnerClient.runTest (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/node_modules/@winglang/sdk/lib/shared-aws/test-runner.inflight.js:27:13)
     │     at async /opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:295:30
     │     at async withSpinner (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/util.js:55:24)
     │     at async testTfAws (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:292:25)
     │     at async testOne (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:124:20)
     │     at async Object.test (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:54:39)
     └     at async Command.<anonymous> (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/cli.js:48:30)

Which now reads like this:

     │ Error: Creating the Wing SDK http client failed - This is likely a bug, please create an issue at https://t.winglang.io/bug or check out Slack winglang.io
     | Here's the full exception:
     │ Error: Invoke failed with message: "Unhandled". Full error: "{"errorType":"SyntaxError","errorMessage":"Unexpected token u in JSON at position 0","trace":["SyntaxError: Unexpected token u in JSON at position 0","    at JSON.parse (<anonymous>)","    at /var/task/index.js:1725:22","    at exports.handler (/var/task/index.js:1733:5)","    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1086:29)"]}"
     │     at FunctionClient.invoke (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/node_modules/@winglang/sdk/lib/shared-aws/function.inflight.js:21:19)
     │     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     │     at async TestRunnerClient.runTest (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/node_modules/@winglang/sdk/lib/shared-aws/test-runner.inflight.js:27:13)
     │     at async /opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:295:30
     │     at async withSpinner (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/util.js:55:24)
     │     at async testTfAws (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:292:25)
     │     at async testOne (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:124:20)
     │     at async Object.test (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/commands/test.js:54:39)
     └     at async Command.<anonymous> (/opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/winglang/dist/cli.js:48:30)

Use Cases

Implementation Notes

Triggered by this issue https://github.com/winglang/wing/issues/3289

The error was, that the generated client

exports.handler = async function(event) {
  return await (await (async () => {
    const $Closure2Client = require_inflight_Closure2()({
      $api_url: JSON.parse(process.env["WING_TOKEN_TFTOKEN_TOKEN_23"]),
      $http_Util: require_http().Util
    });
    const client = new $Closure2Client({});
    if (client.$inflight_init) {
      await client.$inflight_init();
    }
    return client;
  })()).handle(event);
};

and env

WING_FUNCTION_NAME  Handler-c8691000
WING_TARGET tf-aws
WING_TOKEN_TFTOKEN_TOKEN_21 "https://r94p2v0q7l.execute-api.us-east-1.amazonaws.com/prod"

wasn't matching WING_TOKEN_TFTOKEN_TOKEN_23 vs WING_TOKEN_TFTOKEN_TOKEN_21

Component

SDK

Community Notes

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 11 months ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 8 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 5 months ago

Hi,

This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!