3

I am using YAML to pass in a string of comma delimited values for a new relic config file to ignore errors. I need the output to look like this:

"NotFoundError,LocationError,InvalidParamsError"

I tried using folded style and stripping the last newline. My yaml file looks like this:

ignore_errors: >-
  NotFoundError,
  LocationError,
  InvalidParamsError

However, it parses the other newlines as a space in the end giving me something like this:

"NotFoundError, LocationError, InvalidParamsError"

I need it to parse the folded string and not add spaces. Please help.

Alex Pan
  • 4,341
  • 8
  • 34
  • 45

2 Answers2

7

The only way to do this is to quote your string and escape the end of each line with \:

ignore_errors: "\
  NotFoundError,\
  LocationError,\
  InvalidParamsError"
TomDotTom
  • 6,238
  • 3
  • 41
  • 39
3

I don't think the YAML spec will enable you to do what you want, unfortunately (this great SO answer shows the myriad of ways to write multi-line strings in YAML... but doesn't cover your use case). I think your best bet if possible would be to store your error strings as a list, and then use your programming language to format the list. An example in Ruby would be:

require 'yaml'

yaml = <<-YAML
  ignore_errors:
    - NotFoundError
    - LocationError
    - InvalidParamsError
YAML
hash = YAML.load(yaml)
puts hash["ignore_errors"].join(',')

which gives you "NotFoundError,LocationError,InvalidParamsError"

Community
  • 1
  • 1
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122