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

Issue14725 getopt better exceptions #3491

Closed
wants to merge 1 commit into from
Closed

Conversation

burner
Copy link
Member

@burner burner commented Jul 15, 2015

@DmitryOlshansky
Copy link
Member

LGTM

@@ -614,6 +615,24 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
}
}

private void handleConversation(R)(string src, R* receiver,
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by "conversation"? Did you mean conversion?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed

@@ -614,6 +615,24 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
}
}

private void handleConversion(R)(string src, R* receiver,
immutable size_t idx, string option, string file = __FILE__,
long line = __LINE__)
Copy link
Contributor

Choose a reason for hiding this comment

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

size_t line

@@ -614,6 +615,24 @@ private void getoptImpl(T...)(ref string[] args, ref configuration cfg,
}
}

private void handleConversion(R)(string src, R* receiver,
Copy link
Contributor

Choose a reason for hiding this comment

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

here I would keep the order of parameters like of handleOption.

void handleConversation(R)(string option, R receiver, string value, size_t index,
        string file = __FILE__,  size_t line = __LINE__`)

@burner burner force-pushed the issue14725 branch 2 times, most recently from 86be56a to e3858bd Compare July 15, 2015 16:37
else
{
handleConversion(option, val, receiver, i);
}
Copy link
Member

Choose a reason for hiding this comment

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

While I agree that the original code is hard to read, expanding it into 3-line braced blocks seems excessive. What about just leaving out those braces?

Copy link
Member

Choose a reason for hiding this comment

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

I.e., leave the if-block and else-block as separate lines, but just indent them without using braces.

@schveiguy
Copy link
Member

LGTM, @DmitryOlshansky I'll let you pull, if you still think it looks good after all the changes.

@DmitryOlshansky
Copy link
Member

Let's wait a bit on this. I have a proposal brewing that may solve this and many exception-hierarchy issues.

@burner
Copy link
Member Author

burner commented Jul 20, 2015

could you post a reference?

@burner
Copy link
Member Author

burner commented Jul 24, 2015

I'm on holiday for a good 2 weeks, I guess we can wait some more

@DmitryOlshansky
Copy link
Member

I'm on holiday for a good 2 weeks, I guess we can wait some more

And I was about to post that I'm on a cellphone for at least a week. Let's get back to this in ~ 10 days.

@burner
Copy link
Member Author

burner commented Aug 16, 2015

@DmitryOlshansky ping

some simplifications

first round of *receiver replacement

only two places of "to!" left

whitespace

spell error

dcarp fixes

dcarp fixes 2

whitespace

quickfur
@DmitryOlshansky
Copy link
Member

@burner got busy with real life. Ping me back in a couple of days, I'll prepare the proposal

@quickfur
Copy link
Member

quickfur commented Sep 4, 2015

ping
Any news on this?

@burner
Copy link
Member Author

burner commented Sep 4, 2015

well, the bugfix is still good.
But @DmitryOlshansky said he had some magic pill. But he didn't say what is was or when he will present it.

@DmitryOlshansky
Copy link
Member

But @DmitryOlshansky said he had some magic pill. But he didn't say what is was or when he will present it.

Simply put the current fix silently changes exception type. Now users catching ConvException would be surprized to see that they no longer catch the right condition. As for magic - yes I have it, have patience my friends.

@DmitryOlshansky
Copy link
Member

ping
Any news on this?

To start on this as I think I'll wait forever to write a DIP.

What we should have here instead of this "fix" is throw an exception that is both ConversionException (semantics) and GetOptExcpetion (origin). I believe that I found a way to frutifully combine 2 exception hierarchies where one of them is going to be an interface hierarchy. Now my proposal wouldn't stop on just getting hierarchies right we should cover.

Easy creation of exceptions :

alias MyParseException = StandardException!(ParseException, my.module);
alias MyLogicException = StandardException!(LogicException, my.module);

Ease of throwing and creating exceptions:

// writef style formatting
throw exceptionf!MyParseException("This is lazily formatted with %d a number", 42);
// write style formatting
throw exception!MyParseException("This is lazily formatted with ", 42, " a number");

Catching can be done by any of the two: semantic type as in ParseException or by origin (ideally) as ExceptionOrigin!(module.name) or ExceptionOrigin!(package.name). Then:

try{ ... }
catch(ParseException ){ // may be a parse error, possibly in SQL statement
} 
catch(OriginExcpetion!(arsd.mysql)) { // some exception from Mysql package as a whole
}

I believe it's this blend of origin and semantic meaning is the way to go. It's novel I admit but it enables excellent idioms and seems to scale way beyond other hierarchies proposed.

@DmitryOlshansky
Copy link
Member

To start on this as I think I'll wait forever to write a DIP.

The missing piece is proof of concept and that may take a bit of time

@quickfur
Copy link
Member

quickfur commented Sep 7, 2015

I remember you posted about this in the forum, but there wasn't very much response.

Personally I think it's a great idea.

@burner
Copy link
Member Author

burner commented Nov 3, 2015

@DmitryOlshansky ping?

@JackStouffer
Copy link
Member

@DmitryOlshansky If this PR is fixing a genuine problem, then why not pull this instead of waiting for something that might still take a long time. I believe you when you say you have a better solution, but this solution exists now, why not just override this with your changes when they're ready?

@DmitryOlshansky
Copy link
Member

This just changes one exception for another - a breaking change that helps users that didn't expect ConvError but breakscode of others that expect it. Closing one ticket foranew one

@JakobOvrum
Copy link
Member

Yeah, changing the type of a thrown exception breaks code, so let's do it as few times as possible. I agree with @DmitryOlshansky; I think this patch is better applied after his work, when it will be backwards compatible.

@burner
Copy link
Member Author

burner commented Feb 1, 2016

@DmitryOlshansky any news on you DIP

@DmitryOlshansky
Copy link
Member

@DmitryOlshansky any news on you DIP

Not yet, though I intend to process my D-language related backlog soonish.

@wilzbach
Copy link
Member

@DmitryOlshansky any news on you[r] DIP

ping @DmitryOlshansky - ´I like your idea of having multiple exceptions. Any way we can help you?

@DmitryOlshansky
Copy link
Member

´I like your idea of having multiple exceptions. Any way we can help you?

Well so far an attempt to convert Throwable to interface instead of a class exploded in my face at run-time. I need it done and it's the only real obstacle. I will publish the fork of druntime in case there is any interest

@JackStouffer
Copy link
Member

If this is waiting on @DmitryOlshansky's work, then IMO this should be closed, as this will require a rewrite anyway. Right now this is just eating auto-tester time.

@burner
Copy link
Member Author

burner commented Jun 2, 2016

agreeded

@burner burner closed this Jun 2, 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.

8 participants