Skip to content

Commit

Permalink
Show error message of mecab and return 4 when initialization is failed
Browse files Browse the repository at this point in the history
  • Loading branch information
unnonouno committed Oct 12, 2014
1 parent 1fc16b8 commit ec64789
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scripts/mrep
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ if __name__ == '__main__':
else:
printer = mrep.printer.Printer(color_begin, color_end)

parser = mrep.morph.MeCabParser(args.mecab_arg)
try:
parser = mrep.morph.MeCabParser(args.mecab_arg)
except Exception as e:
sys.stderr.write('Fail to initialize MeCab\n')
sys.stderr.write('%s\n' % e)
sys.exit(4)

if len(args.file) > 0:
for file in args.file:
Expand Down
6 changes: 6 additions & 0 deletions test/mrep_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,9 @@ def test_no_pattern(self):
def test_version(self):
out = self.call('--version')
self.assertTrue(__version__ in str(out))

def test_invalid_mecab_arg(self):
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.call('--mecab-arg="--unknown-argument"', '.')

self.assertEqual(4, cm.exception.returncode)

0 comments on commit ec64789

Please sign in to comment.