From 6d54aeb4aa0ad60b2072bdd6c041e6d5c28be80a Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 28 Mar 2024 13:29:33 -0700 Subject: [PATCH] Do not crash if hitting a unsupported intrinsic type (#3077) fix #3073 This still doesn't provide an optimal experience as the error shows up on the void type instead of where it is referenced but solving that is that long standing issue about tracing back where an error should be --- ...dont-crash-unsupported-intrinsic-2024-2-28-19-23-35.md | 8 ++++++++ packages/openapi3/src/schema-emitter.ts | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 .chronus/changes/fix-dont-crash-unsupported-intrinsic-2024-2-28-19-23-35.md diff --git a/.chronus/changes/fix-dont-crash-unsupported-intrinsic-2024-2-28-19-23-35.md b/.chronus/changes/fix-dont-crash-unsupported-intrinsic-2024-2-28-19-23-35.md new file mode 100644 index 0000000000..4cbbc413db --- /dev/null +++ b/.chronus/changes/fix-dont-crash-unsupported-intrinsic-2024-2-28-19-23-35.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/openapi3" +--- + +Do not crash if using an unsupported intrinsic type diff --git a/packages/openapi3/src/schema-emitter.ts b/packages/openapi3/src/schema-emitter.ts index 8177493554..aa1376b9bd 100644 --- a/packages/openapi3/src/schema-emitter.ts +++ b/packages/openapi3/src/schema-emitter.ts @@ -925,7 +925,12 @@ export class OpenAPI3SchemaEmitter extends TypeEmitter< return { nullable: true }; } - throw new Error("Unknown intrinsic type " + name); + reportDiagnostic(this.emitter.getProgram(), { + code: "invalid-schema", + format: { type: name }, + target: intrinsic, + }); + return {}; } programContext(program: Program): Context {