Localdev icon indicating copy to clipboard operation
Localdev copied to clipboard

Add locking / Handle corrupt hosts-localdev

Open ChrisHardie opened this issue 9 years ago • 1 comments

Somehow my /etc/hosts-localdev file became populated in a way that led to errors with list/add/remove operations. It looked like:


---
- domain: domain.com
  ip: 195.5.83.200
195.5.83.200

Then I'd get:

$ localdev list
/Library/Ruby/Gems/2.0.0/gems/psych-2.0.17/lib/psych.rb:376:in `parse': (<unknown>): could not find expected ':' while scanning a simple key at line 4 column 1 (Psych::SyntaxError)
    from /Library/Ruby/Gems/2.0.0/gems/psych-2.0.17/lib/psych.rb:376:in `parse_stream'
    from /Library/Ruby/Gems/2.0.0/gems/psych-2.0.17/lib/psych.rb:324:in `parse'
    from /Library/Ruby/Gems/2.0.0/gems/psych-2.0.17/lib/psych.rb:251:in `load'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/lib/localdev.rb:202:in `block in list'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/lib/localdev.rb:201:in `open'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/lib/localdev.rb:201:in `list'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/lib/localdev.rb:43:in `initialize'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/bin/localdev:22:in `new'
    from /Library/Ruby/Gems/2.0.0/gems/localdev-0.4.0/bin/localdev:22:in `<top (required)>'
    from /usr/local/bin/localdev:23:in `load'
    from /usr/local/bin/localdev:23:in `<main>'

Emptying the hosts-localdev file fixed this. It would be great to have some kind of integrity check on the file, or at least a better error message.

ChrisHardie avatar Jan 18 '16 16:01 ChrisHardie

I think I've traced this issue to a script I'm using that runs localdev twice at the same time. I suspect that without any kind of locking mechanism, the writes to /etc/hosts-localdev are colliding. I can look at adding locking to prevent this, any suggestions about where to start are welcome.

ChrisHardie avatar Nov 08 '16 14:11 ChrisHardie