Skip to content

Commit 132f34f

Browse files
committed
fix: fix MessageLocation.end being corrupted (wrong type) for YAML parse errors
We returned a plain object that stood in for a SourcePosition, but MessageLocation does instanceof SourcePosition checks. Also added a safeguard to the constructor now.
1 parent f2dab64 commit 132f34f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/model/validation/location.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export class MessageLocation {
4646
value: new ProjectSource(this.sourceName, ''),
4747
});
4848
}
49+
50+
if (typeof _start !== 'number' && !(_start instanceof SourcePosition)) {
51+
throw new Error(`start must be either a number or a SourcePosition`);
52+
}
53+
if (typeof _end !== 'number' && !(_end instanceof SourcePosition)) {
54+
throw new Error(`end must be either a number or a SourcePosition`);
55+
}
4956
}
5057

5158
static from(location: LocationLike | undefined): MessageLocation | undefined {

src/schema/schema-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,5 @@ export function getLineEndPosition(targetLine: number, source: ProjectSource): S
256256
}
257257
}
258258

259-
return { line: targetLine, offset: curIndex - 1, column: column };
259+
return new SourcePosition(curIndex - 1, targetLine, column);
260260
}

0 commit comments

Comments
 (0)