Skip to content

Feature Request: Configuration setting that throws error on duplicate registration #4

Open
@brianasapp

Description

@brianasapp

console.warn("declarePersistable warning: declarePersistable : class " + className + " already registered");

On the above line - the user is warned that their original constructor will be overrided, but there is no way to prevent this via configuration.

This becomes dangerous in a larger codebase, when the probability for naming collisions increases. Consider the following example

src/login/form.ts

export class LoginForm {
    constructor() {
        // renders a simple login form
    }
}

declarePersistable(LoginForm);

src/oauth/form.ts

export class LoginForm {
    constructor() {
        // renders an oauth confirmation screen
    }
}

declarePersistable(LoginForm);
// this will overwrite the original LoginForm

Now the simple solution is just to "not do this", but as the number of persistable objects grows - the chances for this type of collision increases as well. Codebases which have additional log statements might mask the severity of this mistake.

My suggestion is that we use some environment variable - perhaps SERIALIJSE_SAFE_MODE to fail loudly anytime the described situation occurs. I would happily open a pull request if we are in agreement.

Thanks for your time,
Brian


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions