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

Do not crash with internal error if /etc/hosts is corrupted #603

Merged
merged 10 commits into from
Apr 30, 2018

Conversation

mchf
Copy link
Member

@mchf mchf commented Jan 30, 2018

@coveralls
Copy link

coveralls commented Jan 30, 2018

Coverage Status

Coverage decreased (-0.01%) to 30.929% when pulling 40add27 on mchf:bnc1077435-internal-error into 9d2de34 on yast:SLE-12-SP3.

@kobliha
Copy link
Member

kobliha commented Jan 30, 2018

Unit test would be more than nice to have...

@mvidner
Copy link
Member

mvidner commented Jan 31, 2018

So the situation is that a config file contains garbage (which manifests as a parsing error down in CFA). It's not random bytes but YaST can't make sense of it.

If we say "Reading /etc/hosts failed" the user will think that the file is not there or the permissions are wrong. We should clearly say that we do not understand the contents.

Copy link
Member

@mvidner mvidner left a comment

Choose a reason for hiding this comment

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

@jreidinger have you dealt with unparseable data yet? I would like to get your opinion to make this consistent.

@@ -370,7 +370,10 @@ def Read(cache)
# Progress step 6/9
ProgressNextStage(_("Reading hostname and DNS configuration...")) if @gui
DNS.Read
Host.Read
if !Host.Read
ret = @gui && Popup.ContinueCancel(_("Reading /etc/hosts failed.\nThe file content is not in expected format.\nIf you continue any existing configuration will be overwritten."))
Copy link
Member

Choose a reason for hiding this comment

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

This                          line                                        is                                                                                                                                                             too long

@@ -370,7 +370,10 @@ def Read(cache)
# Progress step 6/9
ProgressNextStage(_("Reading hostname and DNS configuration...")) if @gui
DNS.Read
Host.Read
if !Host.Read
Copy link
Member

Choose a reason for hiding this comment

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

yast2 host will fail because it does not check the return value or Host.Read, and there are other callers too.

# save hosts to check for changes later
@hosts_init = CFA::Hosts.new
@hosts_init.load
rescue RuntimeError => error
Copy link
Member

Choose a reason for hiding this comment

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

Two problems with this:

  1. RuntimeError is too generic
  2. cannot see where the parse error occurred

In detail:

  1. How about having an exception class across YaST, GarbageDataError, meaning that YaST cannot understand the config files that it's supposed to edit. My point is that we should not let the user proceed and instead have a global rescue, similar to the (500) Internal Error, but labeled (400) "It's Your Fault!!", or "Lost In Translation", or "Cannot Process Such Data".

  2. The actual error is like

    'Augeas parsing/serializing error: Iterated lens matched less than it should at /usr/share/augeas/lenses/dist/hosts.aug:23.12-.42:' (RuntimeError)

    and a specific problem for Augeas is that the line location refers to the lens, or grammar, and not the actual unparseable data :( Line 23 in hosts.aug is

       let lns = ( empty | comment | record ) *
    

    We probably cannot solve that in this PR. See also https://github.com/hercules-team/augeas/wiki/Tracking-down-errors

Copy link
Member

Choose a reason for hiding this comment

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

ideally we shoud log content of file and then we can easily reproduce it.

@jreidinger
Copy link
Member

@teclator
Copy link
Contributor

teclator commented Apr 16, 2018

@mvidner @mchf @jreidinger

The PR for reporting error location in the parsed file was already merged for master but as @mvidner already commented in the PR, this fix is for SP3.

Taking that in account I would like to know which is the state of this PR. Do we plan to continue working on it?, is the patch OK for SP3 as it is (of course after solving the conflicts)?

The PBI for this PR is under the waterline but has not received much attention since a while:

@mchf mchf force-pushed the bnc1077435-internal-error branch from 5fc6792 to 32ccf01 Compare April 30, 2018 06:41
@mchf
Copy link
Member Author

mchf commented Apr 30, 2018

backported updates from #621

@mchf mchf force-pushed the bnc1077435-internal-error branch from 32ccf01 to 40add27 Compare April 30, 2018 07:01
@mchf mchf merged commit fb5a09b into yast:SLE-12-SP3 Apr 30, 2018
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.

6 participants