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

Fix helpful error #1366

Merged
merged 4 commits into from
Jul 1, 2018
Merged

Fix helpful error #1366

merged 4 commits into from
Jul 1, 2018

Conversation

blegat
Copy link
Member

@blegat blegat commented Jun 29, 2018

Closes #1365

@odow
Copy link
Member

odow commented Jun 29, 2018

Should we throw a proper exception type to distinguish the helpful error message from the un-helpful "S not defined"? Because this wasn't caught in tests as it still throws an error.

@mlubin
Copy link
Member

mlubin commented Jun 29, 2018

Can't we just make this work?

if var isa Number && !(value isa Number)
     parse_one_operator_variable(_error, infoexpr, Val(reverse_sense(sense)), esc_nonconstant(var))
    return value
end

@blegat
Copy link
Member Author

blegat commented Jun 29, 2018

I don't understand why it was passing the tests since we check that its an ErrorException and S not defined should be an UndefVarError.

@odow
Copy link
Member

odow commented Jun 29, 2018

The question is whether it is more or less confusing for users. Then you have to say why

@variable(m, 0 <= x)

works but

a = 0
@variable(m, a <= x)

I can see it leading to more confusion than "it never works"

@blegat
Copy link
Member Author

blegat commented Jun 29, 2018

Can't we just make this work?

We should at least throw a warning because it's going to fail badly when it's not constant.
Or we add in the FAQ the meaning of the weird error that is got when it's not constant. I am fine with both.

@mlubin
Copy link
Member

mlubin commented Jun 29, 2018

The confusion always seems to be with

@variable(m, 0 <= x)

I've yet to see a complaint about

a = 0
@variable(m, a <= x)

@odow
Copy link
Member

odow commented Jun 29, 2018

Okay lets change it.

@codecov
Copy link

codecov bot commented Jun 29, 2018

Codecov Report

Merging #1366 into master will increase coverage by 0.06%.
The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1366      +/-   ##
==========================================
+ Coverage   89.44%   89.51%   +0.06%     
==========================================
  Files          24       24              
  Lines        3412     3413       +1     
==========================================
+ Hits         3052     3055       +3     
+ Misses        360      358       -2
Impacted Files Coverage Δ
src/macros.jl 89.8% <57.14%> (+0.4%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f742302...388bec2. Read the comment docs.

@blegat
Copy link
Member Author

blegat commented Jun 29, 2018

I have changed it. It now works instead of erroring :)

src/macros.jl Outdated
@@ -965,18 +965,22 @@ function parsevariable(_error::Function, infoexpr::VariableInfoExpr, sense::Symb
# Variable declaration of the form: var sense value
Copy link
Member

Choose a reason for hiding this comment

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

This comment is out of date, so are the argument names.

Copy link
Member Author

Choose a reason for hiding this comment

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

I explains where the function arguments come from. We should probably rename to lhs rhs though

Copy link
Member Author

Choose a reason for hiding this comment

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

I have refactored it in two methods

test/variable.jl Outdated
@test isequal(mcon[:ubonly],ubonly)
@variable(mcon, ubonly1 <= 1, Int)
@test isequal(mcon[:ubonly1],ubonly1)
@variable(mcon, 1 >= ubonly2, Int)
Copy link
Member

Choose a reason for hiding this comment

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

Make a separate test for this.

@blegat blegat merged commit 647f228 into master Jul 1, 2018
@blegat blegat deleted the bl/helpfulerror branch July 28, 2018 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants