Skip to content

Commit d8df1f1

Browse files
committed
Fix error messages to follow standard: no periods at end
1 parent 7a8672a commit d8df1f1

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/package-url.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,27 @@ class PackageURL {
254254
*/
255255
static fromJSON(json: unknown): PackageURL {
256256
if (typeof json !== 'string') {
257-
throw new Error('JSON string argument is required.')
257+
throw new Error('JSON string argument is required')
258258
}
259259

260260
// Size limit: 1MB to prevent memory exhaustion.
261261
const MAX_JSON_SIZE = 1024 * 1024
262262
if (json.length > MAX_JSON_SIZE) {
263263
throw new Error(
264-
`JSON string exceeds maximum size limit of ${MAX_JSON_SIZE} bytes.`,
264+
`JSON string exceeds maximum size limit of ${MAX_JSON_SIZE} bytes`,
265265
)
266266
}
267267

268268
let parsed
269269
try {
270270
parsed = JSON.parse(json)
271271
} catch (e) {
272-
throw new Error('Invalid JSON string.', { cause: e })
272+
throw new Error('Invalid JSON string', { cause: e })
273273
}
274274

275275
// Validate parsed result is an object.
276276
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
277-
throw new Error('JSON must parse to an object.')
277+
throw new Error('JSON must parse to an object')
278278
}
279279

280280
// Create a safe object without prototype chain to prevent prototype pollution.
@@ -296,7 +296,7 @@ class PackageURL {
296296
*/
297297
static fromObject(obj: unknown): PackageURL {
298298
if (!isObject(obj)) {
299-
throw new Error('Object argument is required.')
299+
throw new Error('Object argument is required')
300300
}
301301
const typedObj = obj as Record<string, unknown>
302302
return new PackageURL(

test/json-export.test.mts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,16 @@ describe('PackageURL JSON/dict export', () => {
243243
it('should validate input and throw appropriate errors', () => {
244244
// Test non-object inputs
245245
expect(() => PackageURL.fromObject('not an object')).toThrow(
246-
'Object argument is required.',
246+
'Object argument is required',
247247
)
248248
expect(() => PackageURL.fromObject(null)).toThrow(
249-
'Object argument is required.',
249+
'Object argument is required',
250250
)
251251
expect(() => PackageURL.fromObject(undefined)).toThrow(
252-
'Object argument is required.',
252+
'Object argument is required',
253253
)
254254
expect(() => PackageURL.fromObject(123)).toThrow(
255-
'Object argument is required.',
255+
'Object argument is required',
256256
)
257257

258258
// Test validation errors
@@ -293,26 +293,26 @@ describe('PackageURL JSON/dict export', () => {
293293
it('should validate input and throw appropriate errors', () => {
294294
// Test non-string inputs
295295
expect(() => PackageURL.fromJSON(123)).toThrow(
296-
'JSON string argument is required.',
296+
'JSON string argument is required',
297297
)
298298
expect(() => PackageURL.fromJSON(null)).toThrow(
299-
'JSON string argument is required.',
299+
'JSON string argument is required',
300300
)
301301
expect(() => PackageURL.fromJSON(undefined)).toThrow(
302-
'JSON string argument is required.',
302+
'JSON string argument is required',
303303
)
304304
expect(() => PackageURL.fromJSON({})).toThrow(
305-
'JSON string argument is required.',
305+
'JSON string argument is required',
306306
)
307307

308308
// Test invalid JSON
309309
expect(() => PackageURL.fromJSON('invalid json')).toThrow(
310-
'Invalid JSON string.',
310+
'Invalid JSON string',
311311
)
312312
expect(() => PackageURL.fromJSON('{"type":"npm","name"}')).toThrow(
313-
'Invalid JSON string.',
313+
'Invalid JSON string',
314314
)
315-
expect(() => PackageURL.fromJSON('')).toThrow('Invalid JSON string.')
315+
expect(() => PackageURL.fromJSON('')).toThrow('Invalid JSON string')
316316

317317
// Test validation of created PackageURL
318318
expect(() =>

0 commit comments

Comments
 (0)