Project

General

Profile

Actions

Feature #14386

closed

Add option to let Kernel.#system raise error instead of returning false

Added by k0kubun (Takashi Kokubun) about 6 years ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:85013]

Description

I sometimes write code like:

system('git pull origin master') || raise('Failed to execute: git pull origin master')
system('bundle check || bundle install') || raise('Failed to execute: bundle check || bundle install')

Using rake, we can simplify the above code to the following one, but there's no way to do that outside Rakefile. (Note that I just want to do the same thing as "bash -e", the error message is actually not important.)

sh 'git pull origin master'
sh 'bundle check || bundle install'

If we add the following option, we can simplify such code even when we're not on a rake task. I'm not sure whether it's a good name or not though.

system 'git pull origin master', exception: true
system 'bundle check || bundle install', exception: true
# => RuntimeError: Command failed with status (1): bundle check || bundle install
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0