Browse Source

add better error handling when failing to read project yaml

libpanel_detach
Alexandros Theodotou 2 months ago
parent
commit
fabb7e034c
Signed by: alex
GPG Key ID: 022EAE42313D70F3
  1. 5
      inc/project.h
  2. 20
      inc/utils/error.h
  3. 32
      src/project.c
  4. 20
      src/utils/error.c
  5. 28
      src/utils/ui.c

5
inc/project.h

@ -547,7 +547,10 @@ _project_compress ( @@ -547,7 +547,10 @@ _project_compress (
* from the most recent backup.
*/
char *
project_get_existing_yaml (Project * self, bool backup);
project_get_existing_yaml (
Project * self,
bool backup,
GError ** error);
/**
* Deep-clones the given project.

20
inc/utils/error.h

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2020 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2020-2021 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
/**
* \file

32
src/project.c

@ -754,7 +754,10 @@ project_create_default ( @@ -754,7 +754,10 @@ project_create_default (
* from the most recent backup.
*/
char *
project_get_existing_yaml (Project * self, bool backup)
project_get_existing_yaml (
Project * self,
bool backup,
GError ** error)
{
/* get file contents */
char * project_file_path = project_get_path (
@ -772,12 +775,9 @@ project_get_existing_yaml (Project * self, bool backup) @@ -772,12 +775,9 @@ project_get_existing_yaml (Project * self, bool backup)
&err);
if (err != NULL)
{
/* Report error to user, and free error */
char str[1200];
sprintf (
str, _ ("Unable to read file: %s"), err->message);
ui_show_error_message (MAIN_WINDOW, true, str);
g_error_free (err);
PROPAGATE_PREFIXED_ERROR (
error, err, _ ("Unable to read file at %s"),
project_file_path);
return NULL;
}
@ -792,8 +792,10 @@ project_get_existing_yaml (Project * self, bool backup) @@ -792,8 +792,10 @@ project_get_existing_yaml (Project * self, bool backup)
g_free (compressed_pj);
if (!ret)
{
HANDLE_ERROR (
err, "%s", _ ("Failed to decompress project file"));
PROPAGATE_PREFIXED_ERROR (
error, err,
_ ("Failed to decompress project file at %s"),
project_file_path);
return NULL;
}
@ -891,9 +893,15 @@ load (const char * filename, const int is_template) @@ -891,9 +893,15 @@ load (const char * filename, const int is_template)
bool use_backup = PROJECT->backup_dir != NULL;
PROJECT->loading_from_backup = use_backup;
char * yaml =
project_get_existing_yaml (PROJECT, use_backup);
g_return_val_if_fail (yaml, -1);
GError * err = NULL;
char * yaml =
project_get_existing_yaml (PROJECT, use_backup, &err);
if (!yaml)
{
HANDLE_ERROR (
err, "%s", _ ("Failed to get existing yaml"));
return -1;
}
g_message ("project from yaml...");
gint64 time_before = g_get_monotonic_time ();

20
src/utils/error.c

@ -1,21 +1,5 @@ @@ -1,21 +1,5 @@
/*
* Copyright (C) 2021-2022 Alexandros Theodotou <alex at zrythm dot org>
*
* This file is part of Zrythm
*
* Zrythm is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Zrythm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
*/
// SPDX-FileCopyrightText: © 2021-2022 Alexandros Theodotou <alex@zrythm.org>
// SPDX-License-Identifier: LicenseRef-ZrythmLicense
#include "gui/widgets/main_window.c"
#include "utils/error.h"

28
src/utils/ui.c

@ -153,6 +153,19 @@ ui_show_message_full ( @@ -153,6 +153,19 @@ ui_show_message_full (
static char buf[40000];
vsprintf (buf, format, args);
/* log the message anyway */
switch (type)
{
case GTK_MESSAGE_ERROR:
g_warning ("%s", buf);
break;
case GTK_MESSAGE_INFO:
default:
g_message ("%s", buf);
break;
}
/* if have UI, also show a message dialog */
if (ZRYTHM_HAVE_UI)
{
GtkDialogFlags flags =
@ -180,21 +193,6 @@ ui_show_message_full ( @@ -180,21 +193,6 @@ ui_show_message_full (
G_CALLBACK (gtk_window_destroy), NULL);
}
}
else
{
switch (type)
{
case GTK_MESSAGE_ERROR:
g_warning ("%s", buf);
break;
case GTK_MESSAGE_INFO:
g_message ("%s", buf);
break;
default:
g_critical ("should not be reached");
break;
}
}
va_end (args);
}

Loading…
Cancel
Save