Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use StringError exception and errors #7

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

Merged
nalimilan merged 2 commits into JuliaStrings:master from ScottPJones:spj/stringerror
Jan 19, 2016

Conversation

@ScottPJones
Copy link
Contributor

@ScottPJones ScottPJones commented Jan 13, 2016

This is intended to make error handling a bit cleaner, and also to potentially improve performance in functions where before it would have had to create a GC frame (because of creating a string to pass to error()).

Copy link
Contributor Author

@nalimilan Bring out the bricks! Let me know what you think.

src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 13, 2016

Choose a reason for hiding this comment

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

Leave strerror here, as you're using it.

Copy link

Current coverage is 88.88%

Merging #7 into master will increase coverage by +0.46% as of 72ba299

@@ master #7 diff @@
======================================
 Files 1 1 
 Stmts 95 108 +13
 Branches 0 0 
 Methods 0 0 
======================================
+ Hit 84 96 +12
 Partial 0 0 
- Missed 11 12 +1

Review entire Coverage Diff as of 72ba299

Powered by Codecov. Updated on successful CI builds.

src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 13, 2016

Choose a reason for hiding this comment

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

I wouldn't make this the same exception type as other errors. It will only happen when loading the package, I can be a standard ErrorException. Ideally, BinDeps would provide a standardize way of checking this, with a specific error.

@ScottPJones ScottPJones force-pushed the spj/stringerror branch 2 times, most recently from 58c4d45 to ee8e9fa Compare January 13, 2016 19:54
Copy link
Contributor Author

@nalimilan Hopefully this addresses everything from your review (except possibly using separate exception types, which I could do in a follow up PR as soon as you've gotten some feedback, or decided yourself what you prefer)

Copy link
Member

I've just posted a message on julia-users: https://groups.google.com/forum/#!topic/julia-users/yMMj5GQi-hY

Copy link
Contributor Author

Ah, I hadn't been thinking of making StringEncodingError an abstract type, and then the other specific types as concrete, I'd thought you were talking about a number of concrete types.
I really like that approach (in addition, in that case, I'd want to lobby for an abstract StringError put in Base, and have my UnicodeError changed to be a concrete subtype of that), as well as new concrete exceptions for iconv.jl (which more and more seems maybe should be StringEncoders.jl or StringEncodings.jl)
Good idea! 👍

Copy link
Contributor Author

As a separate commit, I added support for my understanding of your suggestion on julia-users.
Let me know if that's what you wanted, I do think it made things cleaner!

src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 14, 2016

Choose a reason for hiding this comment

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

I don't see the point of this GeneralError type. The idea behind using specific exception types was precisely that they can be adapted to the specific information you need to convey. In my message to julia-users, I simplified the typology a bit, but the other constants from above should all be replaced with an exception type.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

The point of a GeneralError type was to be able (in the future) to have the actual messages table driven, based on the locale, so a French locale could display error strings in French, for example.

Copy link
Member

@nalimilan nalimilan Jan 15, 2016

Choose a reason for hiding this comment

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

Translating error messages is another big issue that should be tackled in Julia more broadly. Let's keep that out of scope for now.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

Right, but this does nothing more than what UnicodeError already does in Base, to allow for the format strings to be constant - which is what allows the error handling to be done without forcing the entire function to always push a GC frame (I know that Yuyichao has talked about changing things so that that is not so bad, by only doing that along branches that do the creating, but I'm not sure what the status of the in v0.4.x or master).
Yes, the whole locale business is something to think about for the future, but I think having GeneralError which greatly simplifies making the specific exception types, is well worth having here.

Copy link
Member

@nalimilan nalimilan Jan 15, 2016

Choose a reason for hiding this comment

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

I think it would be better to have all StringEncodingError subtypes contain those fields instead, and get rid of GeneraError. That way, you can make args a tuple of the right length for each type.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

But wouldn't that mean adding a lot of code to have specific show methods for every single type?

Copy link
Member

@nalimilan nalimilan Jan 15, 2016

Choose a reason for hiding this comment

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

No, because you should be able to write a generic function for StringEncodingError.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

Hmm, OK, I'll try to figure out how to do that.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

OK, wasn't as painful as I thought it would be, but does mean instead of a single value for each subtype of StringEncodingError, they need to copy the three that GeneralError had.
Let me know what you think of this commit, thanks!

Copy link
Contributor Author

Hope I didn't miss anything, and that you think this PR is a net improvement. Thanks again for spending the time to improve strings on Julia & being patient with these PRs to your package!

src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 15, 2016

Choose a reason for hiding this comment

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

Sorry, this looks good, but I've come to think that instead of storing a msg field which would be identical for all instances; it would be better to have message(::Type{InvalidEncodingError}), etc., functions which will return the message template. Then it should be OK.

That should also allow you to get rid of inner constructors (or of most of them).

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

Hehe, no problem at all, sounds like a good idea! Just hope you are OK with all the time on this, thanks!

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

As I've been changing it to use message, I had a thought, that maybe this loses some important flexibility. If you use constructors, it you can have different messages, based on the number or types of the arguments to the constructors, but with this scheme, how would you manage that?
For this particular package, at least now, it probably doesn't matter, but I still am thinking about what we'd want for a much more flexible and efficient general error scheme for Julia.

Copy link
Member

@nalimilan nalimilan Jan 15, 2016

Choose a reason for hiding this comment

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

You could still define the method to return the msg field if it's actually there for the considered type. So I don't think we'd lose in generality at all.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 15, 2016

Choose a reason for hiding this comment

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

Another issue, is that I think it adds a dynamic dispatch when you actually do call show, whereas before, that was not necessary.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 16, 2016

Choose a reason for hiding this comment

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

Ok, I'll try that.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 16, 2016

Choose a reason for hiding this comment

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

I tried a slightly different method that looked a bit cleaner - let me know what you think, I added a subtype for StringEncodingErrors that don't take any arguments, makes the show() method for thos just a simple one-liner.

Copy link
Member

@nalimilan nalimilan Jan 16, 2016

Choose a reason for hiding this comment

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

Rather than an abstract type, I'd prefer if you used a type union for show. Also put the two show methods at the same place for clarity. That way, the type tree won't reflect implementation details: subtypes(StringEncodingError) will only return interesting information for the user.

After that, we should be done!

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 16, 2016

Choose a reason for hiding this comment

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

OK, done!

@ScottPJones ScottPJones force-pushed the spj/stringerror branch 2 times, most recently from c419535 to 7444825 Compare January 16, 2016 17:28
src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 16, 2016

Choose a reason for hiding this comment

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

Again, no need to use the longer parametric function syntax here, just put the Union after the argument (also, putting the function on two lines would be better).

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 16, 2016

Choose a reason for hiding this comment

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

OK, that's just how I've usually seen it in the code in Base - will change.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 16, 2016

Choose a reason for hiding this comment

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

It actually turned out to be a few characters longer - before I had message(T), now it is message(typeof(exc)), but that's fine.

Copy link
Member

@nalimilan nalimilan Jan 16, 2016

Choose a reason for hiding this comment

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

As you wish, but it would be nice to make the line shorter by splitting it.

Copy link
Contributor Author

@nalimilan Does this look OK now?

src/iconv.jl Outdated
Copy link
Member

@nalimilan nalimilan Jan 18, 2016

Choose a reason for hiding this comment

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

InvalidSequenceError would be more precise and consistent with the other one.

Copy link
Contributor Author

@ScottPJones ScottPJones Jan 18, 2016

Choose a reason for hiding this comment

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

The reason this was separate, was that this one didn't have the byte sequence available.
Do you have a good solution for that?

Copy link
Member

@nalimilan nalimilan Jan 18, 2016

Choose a reason for hiding this comment

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

Ah, I see. Then just remove that branch, as I don't think it can happen (the call doesn't pass any input data...). Anyway we'll get a generic error if it happens.

Copy link
Member

Thanks. Please squash the PR into a single commit.

Implement Milan's idea for abstract StringEncodingError
Changes per Milan's review:
generalerror -> iconv_error
Removal of iconv: from most error messages
Addition of more specific exceptions: IConvError, OutputBufferError, InvalidBytesError
Eliminate GeneralError, per review
Remove iconv_error, modulename, clean up show, per review
Copy link
Contributor Author

@nalimilan Anything else? I added one extra commit to add some more tests and make codecov-io stop complaining, I can squash that in as well.

Copy link
Member

OK, looks good, thanks!

nalimilan added a commit that referenced this pull request Jan 19, 2016
@nalimilan nalimilan merged commit 76e0e89 into JuliaStrings:master Jan 19, 2016
@ScottPJones ScottPJones deleted the spj/stringerror branch January 19, 2016 23:13
Copy link
Contributor Author

Thank you! I enjoyed getting all your input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /