Skip to content

Refuse to override builtin file type#379

Merged
bajtos merged 1 commit intomasterfrom
fix/reject-file-type-converter
Oct 31, 2016
Merged

Refuse to override builtin file type#379
bajtos merged 1 commit intomasterfrom
fix/reject-file-type-converter

Conversation

@bajtos
Copy link
Member

@bajtos bajtos commented Oct 27, 2016

Arguments of { type: 'file' } are handled specially by strong-remoting and don't go through the usual TypeConverter path.

This causes problems in LoopBack applications with a model called "File", which registers a type converter for "file" (the name is case insensitive).

In this patch, we are modifying TypeRegistry to throw an error when the caller attempts to override the built-in "file" type.

Connect to strongloop/loopback#2554

On the second thought, I think we should add file to the list of reserved types and disallow developers to create models called File, starting with LoopBack 3.0. It is already not possible to create models like Object or Number, therefore I think it makes sense to extend this rule to File too.
I believe this will require the smallest amount of code changes and have the lowest maintenance costs in the future.

See also #370

@gunjpan or @deepakrkris please review
cc @fabien @ritch

Copy link
Contributor

@gunjpan gunjpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL at minor comments, other than that, LGTM

typeName = typeName.toLowerCase();

if (typeName === 'file') {
throw new Error('Cannot override built-in "file" type.');
Copy link
Contributor

@gunjpan gunjpan Oct 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bajtos : Please change this to throw a globalized error message, for example:

  if(typename === 'file'){
    var eMsg = g.f('Cannot {{override}} built-in "{{file}}" type.');
    throw new Error(eMsg);
  }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't see it being caught anywhere. So, I am assuming that it will bubble up and eventually handled. Correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't see it being caught anywhere. So, I am assuming that it will bubble up and eventually handled. Correct?

It will bubble up and crash the app at startup, which is my intent. Let the user know about the problem immediately at startup, rather than later when some of their requests start failing.

@bajtos bajtos force-pushed the fix/reject-file-type-converter branch from 1b03682 to bda97dc Compare October 31, 2016 17:21
Arguments of { type: 'file' } are handled specially by strong-remoting
and don't go through the usual TypeConverter path.

This causes problems in LoopBack applications with a model called
"File", which registers a type converter for "file" (the name is case
insensitive).

In this commit, we are modifying TypeRegistry to throw an error when
the caller attempts to override the built-in "file" type.
@bajtos bajtos force-pushed the fix/reject-file-type-converter branch from bda97dc to 2c4cc6e Compare October 31, 2016 17:21
@bajtos
Copy link
Member Author

bajtos commented Oct 31, 2016

@gunjpan fixed, PTAL again

Copy link
Contributor

@gunjpan gunjpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@bajtos bajtos merged commit 4379639 into master Oct 31, 2016
@bajtos bajtos deleted the fix/reject-file-type-converter branch October 31, 2016 17:54
@bajtos bajtos removed the #review label Oct 31, 2016
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

Successfully merging this pull request may close these issues.

3 participants