Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: unknown format #34

Open
perry-mitchell opened this issue Dec 13, 2023 · 0 comments
Open

Error: unknown format #34

perry-mitchell opened this issue Dec 13, 2023 · 0 comments

Comments

@perry-mitchell
Copy link

perry-mitchell commented Dec 13, 2023

Receiving an unexpected error when trying to parse random strings. I'd expect it to return null like in the documentation, not throw an error:

import { FinnishSSN } from "finnish-ssn";
import { parse as parseSweSSN } from "sweden-national-id";

export function isValidSSN(ssn: string): boolean {
    if (FinnishSSN.validate(ssn)) return true;
    const sweSSN = parseSweSSN(ssn);
    if (sweSSN) return true;
    return false;
}
Error: unknown format
     at format (node_modules/sweden-national-id/dist/format.js:24:19)
     at parse (node_modules/sweden-national-id/dist/national-id-number.js:24:50)
     at isValidSSN (file:///home/perry/<snip>/bots/dist/test/projects/shared/library/ssn.js:6:20)
     at validateStringWithoutPII (file:///home/perry/<snip>/bots/dist/test/projects/shared/schemaHelpers.js:136:13)
     at Context.<anonymous> (file:///home/perry/<snip>/bots/dist/test/test/shared/unit/schemaHelpers.spec.js:40:20)
     at process.processImmediate (node:internal/timers:478:21)

Value can be literally anything, and it breaks.

For instance, I was testing segments of a piece of text, looking for a Swedish SSN, and it broke on every value:

export function isValidSSN(ssn: string): boolean {
    if (FinnishSSN.validate(ssn)) return true;
    try {
        const sweSSN = parseSweSSN(ssn);
        if (sweSSN) return true;
    } catch (err) {
        console.error("SSN ERR:    "+ssn);
        return false;
    }
    return false;
}
SSN TEST:    my
SSN TEST:    number
SSN TEST:    is
SSN TEST:    my
SSN TEST:    number
SSN TEST:    is
SSN TEST:    0439200192.

I'm using Node 20 under docker, with typescript v5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant