Skip to content

Commit

Permalink
fix(cli): Improve error logging in AsyncAPI v3 parser when parsing lo…
Browse files Browse the repository at this point in the history
…cation headers. (#6175)

* fix(cli): Improve error logging in AsyncAPI v3 parser when parsing location headers.

* chore: update changelog
  • Loading branch information
eyw520 authored Feb 26, 2025
1 parent 4d14274 commit d4ae8ba
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions fern/pages/changelogs/cli/2025-02-26.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.54.0-rc11
**`(fix):`** Improve error logging in AsyncAPI v3 parser when parsing location headers.

Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,25 @@ function convertChannelParameterLocation(location: string): {
type: "header" | "path" | "payload";
parameterKey: string;
} {
const [messageType, parameterKey] = location.split("#/");
if (messageType == null || parameterKey == null) {
throw new Error(`Invalid location format: ${location}`);
}
if (!messageType.startsWith(LOCATION_PREFIX)) {
throw new Error(`Invalid location format: ${location}`);
}
const type = messageType.substring(LOCATION_PREFIX.length);
if (type !== "header" && type !== "path" && type !== "payload") {
throw new Error(`Invalid message type: ${type}. Must be one of: header, path, payload`);
try {
const [messageType, parameterKey] = location.split("#/");
if (messageType == null || parameterKey == null) {
throw new Error(`Invalid location format: ${location}; unable to parse message type and parameter key`);
}
if (!messageType.startsWith(LOCATION_PREFIX)) {
throw new Error(`Invalid location format: ${location}; expected ${LOCATION_PREFIX} prefix`);
}
const type = messageType.substring(LOCATION_PREFIX.length);
if (type !== "header" && type !== "path" && type !== "payload") {
throw new Error(`Invalid message type: ${type}. Must be one of: header, path, payload`);
}
return { type, parameterKey };
} catch (error) {
throw new Error(
`Invalid location format: ${location}; see here for more details: ` +
"https://www.asyncapi.com/docs/reference/specification/v3.0.0#runtimeExpression"
);
}
return { type, parameterKey };
}

function getServerNameFromServerRef(
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
- changelogEntry:
- summary: Improve error logging in AsyncAPI v3 parser when parsing location headers.
type: fix
irVersion: 55
version: 0.54.0-rc11

- changelogEntry:
- summary: Migrate generators.yml without any specs.
type: chore
Expand Down

0 comments on commit d4ae8ba

Please sign in to comment.