ingydotnet/yaml-pm — pull request #142 by werekraken (2014-12-17 23:22:26+00:00)
Title: Fix error messaging and prevent silent write failure.

Hey Ingy,

There are 3 related patches in my pull request.

The first is to fix a literal '\n' showing up in error messages. This was also reported in issue 113, "verbatim '\n' in error messages [rt.cpan.org #68845]".

Pre-Patch:

$ git checkout 3092ef >/dev/null; perl -e "use lib 'lib'; use YAML; YAML::LoadFile('none')"
Previous HEAD position was 65a2bbb... Prevent silent write failure when DumpFile is passed a filename.
HEAD is now at 3092efd... CPAN Release 1.13
YAML Error: Couldn't open none for input:\n
Code: YAML_LOAD_ERR_FILE_INPUT
at lib/YAML.pm line 70.

Post-Patch:

$ git checkout e1a17c >/dev/null; perl -e "use lib 'lib'; use YAML; YAML::LoadFile('none')"
Previous HEAD position was 3092efd... CPAN Release 1.13
HEAD is now at e1a17cb... Fix literal '\n' in error messages.
YAML Error: Couldn't open none for input:

Code: YAML_LOAD_ERR_FILE_INPUT
at lib/YAML.pm line 70.

The second is to fix $! getting clobbered (overwritten) before it is passed by value into YAML::Mo::Object->die() (Both above outputs do not have this patch, patched output below). I think this covers issue 118, "Specification for LoadFile (and others) does not state what occurs on error [rt.cpan.org #72571]".

Post-Patch:

$ git checkout 878250 >/dev/null; perl -e "use lib 'lib'; use YAML; YAML::LoadFile('none')"
Previous HEAD position was e1a17cb... Fix literal '\n' in error messages.
HEAD is now at 8782501... Prevent errorno messages from being clobbered before being printed.
YAML Error: Couldn't open none for input:
No such file or directory
Code: YAML_LOAD_ERR_FILE_INPUT
at lib/YAML.pm line 76.

The third is to prevent silent write failure when YAML::DumpFile is passed a filename (Both pre-patch and post-patch outputs below).

Pre-Patch:

$ git checkout 878250 >/dev/null; perl -e "use lib 'lib'; use YAML; YAML::DumpFile('/mnt/nospace', '')"
HEAD is now at 8782501... Prevent errorno messages from being clobbered before being printed.

Post-Patch:

$ git checkout 65a2bb >/dev/null; perl -e "use lib 'lib'; use YAML; YAML::DumpFile('/mnt/nospace', '')"
Previous HEAD position was 8782501... Prevent errorno messages from being clobbered before being printed.
HEAD is now at 65a2bbb... Prevent silent write failure when DumpFile is passed a filename.
YAML Error: Error closing /mnt/nospace:
No space left on device
Code: YAML_DUMP_ERR_FILE_OUTPUT_CLOSE
at lib/YAML.pm line 68.

Let me know if you need any additional information.

Thanks,
werekraken