From 74f7a2435d0fdfc0c59ab9afcf7e7a609bde41d6 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Fri, 28 May 2021 11:47:54 +0900 Subject: [PATCH] Added an error message suggesting to specify the character encoding option --- lib/youplot/command.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/youplot/command.rb b/lib/youplot/command.rb index 84497e6..d6af939 100644 --- a/lib/youplot/command.rb +++ b/lib/youplot/command.rb @@ -102,8 +102,17 @@ module YouPlot end def read_dsv(input) - input = input.dup.force_encoding(options[:encoding]).encode('utf-8') if options[:encoding] - DSV.parse(input, options[:delimiter], options[:headers], options[:transpose]) + if options[:encoding] + input.force_encoding(options[:encoding]) + .encode!('utf-8') + end + begin + DSV.parse(input, options[:delimiter], options[:headers], options[:transpose]) + rescue CSV::MalformedCSVError => e + warn 'Failed to parse the text. ' + warn 'Please try to set the correct character encoding with --encoding option.' + raise e + end end def create_plot