Skip to content

Commit

Permalink
Fail with an error message when lisp import processing fails in CLI m…
Browse files Browse the repository at this point in the history
…ode (#347)

* Fail with an error message when lisp import processing fails in CLI mode

Returns a non-zero exit code and prints an error message.

* Fix creating zero-size file when creating a package from CLI fails

Move opening the package output file right before writing. Opening the
file already creates a zero-size file on the disk, presumably when the
file is closed in the destructor.
  • Loading branch information
lukash authored Jan 17, 2024
1 parent b59d2d0 commit 23c1b77
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,6 @@ int main(int argc, char *argv[])
qDebug() << "Opened package" << pkg.name;
}

QFile file(pkgPath);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << QString("Could not open %1 for writing.").arg(pkgPath);
return 1;
}

if (!lispPath.isEmpty()) {
QFile f(lispPath);
if (!f.open(QIODevice::ReadOnly)) {
Expand All @@ -854,6 +848,11 @@ int main(int argc, char *argv[])

QFileInfo fi(f);
pkg.lispData = loader.lispPackImports(f.readAll(), fi.canonicalPath());
// Empty array means an error. Otherwise, CodeLoader.lispPackImports() always returns data.
if (pkg.lispData.isEmpty()) {
qWarning() << "Errors when processing lisp imports.";
return 1;
}
f.close();

qDebug() << "Read lisp script done";
Expand All @@ -873,6 +872,12 @@ int main(int argc, char *argv[])
qDebug() << "Read qml script done";
}

QFile file(pkgPath);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << QString("Could not open %1 for writing.").arg(pkgPath);
return 1;
}

file.write(loader.packVescPackage(pkg));
file.close();

Expand Down

0 comments on commit 23c1b77

Please sign in to comment.