Improve error messages for missing export presets when using --export

- Display a specific error message if the project doesn't have an
  `export_presets.cfg` file.
- Display a list of detected export presets if an invalid export
  preset name is supplied.
This commit is contained in:
Hugo Locurcio 2021-04-06 01:44:15 +02:00
parent f4b82814f8
commit 09f38ea215
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C

View File

@ -794,17 +794,27 @@ void EditorNode::_fs_changed() {
}
preset.unref();
}
if (preset.is_null()) {
export_error = vformat(
"Invalid export preset name: %s. Make sure `export_presets.cfg` is present in the current directory.",
preset_name);
DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
if (da->file_exists("res://export_presets.cfg")) {
export_error = vformat(
"Invalid export preset name: %s.\nThe following presets were detected in this project's `export_presets.cfg`:\n\n",
preset_name);
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); ++i) {
// Write the preset name between double quotes since it needs to be written between quotes on the command line if it contains spaces.
export_error += vformat(" \"%s\"\n", EditorExport::get_singleton()->get_export_preset(i)->get_name());
}
} else {
export_error = "This project doesn't have an `export_presets.cfg` file at its root.\nCreate an export preset from the \"Project > Export\" dialog and try again.";
}
} else {
Ref<EditorExportPlatform> platform = preset->get_platform();
const String export_path = export_defer.path.is_empty() ? preset->get_export_path() : export_defer.path;
if (export_path.is_empty()) {
export_error = vformat("Export preset '%s' doesn't have a default export path, and none was specified.", preset_name);
export_error = vformat("Export preset \"%s\" doesn't have a default export path, and none was specified.", preset_name);
} else if (platform.is_null()) {
export_error = vformat("Export preset '%s' doesn't have a matching platform.", preset_name);
export_error = vformat("Export preset \"%s\" doesn't have a matching platform.", preset_name);
} else {
Error err = OK;
if (export_defer.pack_only) { // Only export .pck or .zip data pack.
@ -817,7 +827,7 @@ void EditorNode::_fs_changed() {
String config_error;
bool missing_templates;
if (!platform->can_export(preset, config_error, missing_templates)) {
ERR_PRINT(vformat("Cannot export project with preset '%s' due to configuration errors:\n%s", preset_name, config_error));
ERR_PRINT(vformat("Cannot export project with preset \"%s\" due to configuration errors:\n%s", preset_name, config_error));
err = missing_templates ? ERR_FILE_NOT_FOUND : ERR_UNCONFIGURED;
} else {
err = platform->export_project(preset, export_defer.debug, export_path);
@ -827,13 +837,13 @@ void EditorNode::_fs_changed() {
case OK:
break;
case ERR_FILE_NOT_FOUND:
export_error = vformat("Project export failed for preset '%s', the export template appears to be missing.", preset_name);
export_error = vformat("Project export failed for preset \"%s\". The export template appears to be missing.", preset_name);
break;
case ERR_FILE_BAD_PATH:
export_error = vformat("Project export failed for preset '%s', the target path '%s' appears to be invalid.", preset_name, export_path);
export_error = vformat("Project export failed for preset \"%s\". The target path \"%s\" appears to be invalid.", preset_name, export_path);
break;
default:
export_error = vformat("Project export failed with error code %d for preset '%s'.", (int)err, preset_name);
export_error = vformat("Project export failed with error code %d for preset \"%s\".", (int)err, preset_name);
break;
}
}