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

Follow up on #4660: new app error msg #4743

Merged

Conversation

rhcarvalho
Copy link
Contributor

Given a JSON template with invalid syntax:

$ cat bad-template.json
{
"there should not be a trailing comma": "here",
}

Before #4660, oc new-app produced this error message:

$ oc new-app bad-template.json
error: no image or template matched "bad-template.json"

After:

$ oc new-app bad-template.json
error: invalid character '}' looking for beginning of object key string

But @smarterclayton commented that the implementation was leaking an abstraction, thus, this follow up.

@rhcarvalho
Copy link
Contributor Author

@smarterclayton what do you think of this approach?

You suggested of a different type of error that would not be ignored by resolvers, but there are many places in the code path of new-app that ignores errors and/or replace them with new errors, what makes it difficult to solve the abstraction leak with a simple change, or at least I could not find one simple change that would do the trick.

The current solution here is to catch the SyntaxError and print a message to Stderr immediately, what would make it like this:

$ oc new-app bad-template.json 
bad-template.json at offset 51: invalid character '}' looking for beginning of object key string
error: no image or template matched "bad-template.json"

The problem with this is that it might stutter:

$ oc new-app -f bad-template.json 
bad-template.json at offset 51: invalid character '}' looking for beginning of object key string
error: invalid character '}' looking for beginning of object key string

@rhcarvalho rhcarvalho mentioned this pull request Sep 21, 2015
@danmcp
Copy link

danmcp commented Oct 16, 2015

@smarterclayton Bump

@openshift-bot openshift-bot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 22, 2015
@danmcp
Copy link

danmcp commented Jan 19, 2016

@csrwng @bparees Review please.

@bparees
Copy link
Contributor

bparees commented Jan 19, 2016

@rhcarvalho squash please.
@smarterclayton approve?

lgtm otherwise.

@csrwng
Copy link
Contributor

csrwng commented Jan 19, 2016

lgtm

@rhcarvalho rhcarvalho force-pushed the followup-pr4660-new-app-err-msg branch from 0c0718d to 99a349e Compare January 20, 2016 14:20
@rhcarvalho
Copy link
Contributor Author

This got quite aged. Here's how it is affecting the scenario described in the PR description:

$ cat template.json 
{"broken

a. Current state before the PR:

$ oc new-app template.json 
error: invalid character '\n' in string literal

b. With the changes introduced in this PR:

$ oc new-app template.json 
template.json at offset 9: invalid character '\n' in string literal
error: no match for "template.json", specify --allow-missing-images to use this image name.

The 'new-app' command will match arguments to the following types:

  1. Images tagged into image streams in the current project or the 'openshift' project
     - if you don't specify a tag, we'll add ':latest'
  2. Images in the Docker Hub, on remote registries, or on the local Docker engine
  3. Templates in the current project or the 'openshift' project
  4. Git repository URLs or local paths that point to Git repositories

--allow-missing-images can be used to point to an image that does not exist yet.

See 'new-app' for examples.

Hmm new-app changed considerably meanwhile, that it makes my change produce a worse output then the current state IMHO.

The initial motivator for this change was to try to address @smarterclayton's comment about leaking an abstraction...

Do we still want to fix the abstraction leak? If so, I'd look for a different solution. Otherwise I'll just close this.

@bparees
Copy link
Contributor

bparees commented Jan 20, 2016

i'd still like to clean it up, i kinda hate where that isFile logic lives right now.

@bparees
Copy link
Contributor

bparees commented Jan 20, 2016

as for the right fix... yeah if we had an exact match (of the file "template.json" in this case) we should not be also assuming it might be an image name for an image we couldn't even find.

(if there were an image named "template.json", that would be a different story.... in that case we should return a multiple match error, they should then specify the file explicitly, and then they should get an error that the file is invalid)

@rhcarvalho
Copy link
Contributor Author

i kinda hate where that isFile logic lives right now.

Yep, it's ugly, but what worked back then. I'm +1 on making it better.

I'll probably defer finding a more appropriate fix post dev-cut, is that alright?

@bparees
Copy link
Contributor

bparees commented Jan 20, 2016

I'll probably defer finding a more appropriate fix post dev-cut, is that alright?

yup, that's the right priority.

@smarterclayton
Copy link
Contributor

smarterclayton commented Jan 20, 2016 via email

@bparees
Copy link
Contributor

bparees commented Jan 20, 2016

it seems a little confusing, but i could be convinced to live with it and merge this if you're actually ok with it :)

@rhcarvalho
Copy link
Contributor Author

I'm not ok with the output after the current state of this PR. It's very easy to miss the error message in the first line. I'd miss it if I was not intentionally looking for it.

@rhcarvalho
Copy link
Contributor Author

(note to self) this PR might simply die after #6670 merges.

@rhcarvalho rhcarvalho force-pushed the followup-pr4660-new-app-err-msg branch 2 times, most recently from be77e37 to 46b8b97 Compare February 5, 2016 16:22
@rhcarvalho
Copy link
Contributor Author

The little improvement that was present here and not included in #6670 is printing the offset where a syntax error happened:

$ oc new-app template.json 
error: unable to load template file "template.json": at offset 9: invalid character '\n' in string literal
error: no match for "template.json"

...

@bparees PTAL [test]

@rhcarvalho rhcarvalho force-pushed the followup-pr4660-new-app-err-msg branch from 46b8b97 to df1f5e9 Compare February 5, 2016 16:25
@smarterclayton
Copy link
Contributor

LGTM - maybe add a test for it?

@rhcarvalho
Copy link
Contributor Author

@smarterclayton the test in test/cmd/newapp.sh includes the offset already, do you mean something more than that?

@bparees
Copy link
Contributor

bparees commented Feb 5, 2016

lgtm [merge]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test Running (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/861/)

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/4866/) (Image: devenv-rhel7_3346)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to df1f5e9

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to df1f5e9

openshift-bot pushed a commit that referenced this pull request Feb 5, 2016
@openshift-bot openshift-bot merged commit 6e75bd5 into openshift:master Feb 5, 2016
@rhcarvalho rhcarvalho deleted the followup-pr4660-new-app-err-msg branch February 5, 2016 22:14
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.

None yet

6 participants