Skip to content

Commit 34bc96f

Browse files
committed
cstrans-df-run: simplify the interface of transformRunLine()
Exception are now caught by the caller. No change in behavior intended with this commit.
1 parent 25965d4 commit 34bc96f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

src/cstrans-df-run.cc

+19-21
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class DockerFileTransformer {
5050
const bool verbose_; ///< --verbose on cmd-line
5151
int lineNum_; ///< line number being read
5252

53-
bool transformRunLine(std::string *);
53+
void transformRunLine(std::string *);
5454

5555
/// match ... in RUN ...
5656
const RE reLineRun_ = RE("^RUN (.*)$");
@@ -163,30 +163,23 @@ std::string runLineFromExecList(const TStringList &execList)
163163
return runLine;
164164
}
165165

166-
bool DockerFileTransformer::transformRunLine(std::string *pRunLine)
166+
void DockerFileTransformer::transformRunLine(std::string *pRunLine)
167167
{
168168
// start with the prefix specified on cmd-line
169169
TStringList execList = prefixCmd_;
170170

171-
try {
172-
boost::smatch sm;
173-
if (boost::regex_match(*pRunLine, sm, reLineRunExec_))
174-
// RUN ["cmd", "arg1", "arg2", ...]
175-
appendExecArgs(&execList, sm[1]);
171+
boost::smatch sm;
172+
if (boost::regex_match(*pRunLine, sm, reLineRunExec_))
173+
// RUN ["cmd", "arg1", "arg2", ...]
174+
appendExecArgs(&execList, sm[1]);
176175

177-
else if (boost::regex_match(*pRunLine, sm, reLineRun_))
178-
// RUN arbitrary shell code...
179-
appendShellExec(&execList, sm[1]);
176+
else if (boost::regex_match(*pRunLine, sm, reLineRun_))
177+
// RUN arbitrary shell code...
178+
appendShellExec(&execList, sm[1]);
180179

181-
else
182-
// should never happen
183-
throw std::runtime_error("internal error");
184-
}
185-
catch (const std::runtime_error &e) {
186-
std::cerr << prog_name << "error: parsing error on line "
187-
<< lineNum_ << ": " << e.what() << std::endl;
188-
return false;
189-
}
180+
else
181+
// should never happen
182+
throw std::runtime_error("internal error");
190183

191184
const std::string newRunLine = runLineFromExecList(execList);
192185
if (verbose_) {
@@ -197,7 +190,6 @@ bool DockerFileTransformer::transformRunLine(std::string *pRunLine)
197190

198191
// return the result of a successful transformation
199192
*pRunLine = newRunLine;
200-
return true;
201193
}
202194

203195
bool DockerFileTransformer::transform(std::istream &in, std::ostream &out)
@@ -237,8 +229,14 @@ bool DockerFileTransformer::transform(std::istream &in, std::ostream &out)
237229
continue;
238230

239231
// transform the linearized RUN line
240-
if (!this->transformRunLine(&runLine))
232+
try {
233+
this->transformRunLine(&runLine);
234+
}
235+
catch (const std::runtime_error &e) {
236+
std::cerr << prog_name << "error: parsing error on line "
237+
<< lineNum_ << ": " << e.what() << std::endl;
241238
anyError = true;
239+
}
242240

243241
// write the transformed RUN line and update state
244242
out << runLine << std::endl;

0 commit comments

Comments
 (0)