Skip to content

Commit

Permalink
Improve error messages style
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Feb 4, 2018
1 parent dee32ec commit db5458b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 67 deletions.
18 changes: 9 additions & 9 deletions src/cache.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* cache.c
* Copyright (c) 2014-2017 Arkadiusz Bokowy
* Copyright (c) 2014-2018 Arkadiusz Bokowy
*
* This file is a part of cmusfm.
*
Expand Down Expand Up @@ -122,8 +122,8 @@ void cmusfm_cache_update(const scrobbler_trackinfo_t *sb_tinf) {
struct cmusfm_cache_record *record;
size_t record_size;

debug("cache update: %ld", sb_tinf->timestamp);
debug("payload: %s - %s (%s) - %d. %s (%ds)",
debug("Cache update: %ld", sb_tinf->timestamp);
debug("Payload: %s - %s (%s) - %d. %s (%ds)",
sb_tinf->artist, sb_tinf->album, sb_tinf->album_artist,
sb_tinf->track_number, sb_tinf->track, sb_tinf->duration);

Expand Down Expand Up @@ -160,7 +160,7 @@ void cmusfm_cache_submit(scrobbler_session_t *sbs) {
size_t rd_len, record_size;
char *ptr;

debug("cache submit");
debug("Cache submit");

if ((f = fopen(cmusfm_cache_file, "r")) == NULL)
return;
Expand All @@ -187,21 +187,21 @@ void cmusfm_cache_submit(scrobbler_session_t *sbs) {
/* validate record type and first-stage data integration */
if (record->signature != CMUSFM_CACHE_SIGNATURE ||
record->checksum1 != get_cache_record_checksum1(record)) {
fprintf(stderr, "error: invalid cache record signature\n");
debug("signature: %x, checksum: %x", record->signature, record->checksum1);
fprintf(stderr, "ERROR: Invalid cache record signature\n");
debug("Signature: %x, checksum: %x", record->signature, record->checksum1);
goto return_failure;
}

record_size = get_cache_record_size(record);
debug("record size: %ld", record_size);
debug("Record size: %ld", record_size);

/* break if current record is truncated */
if ((void *)record - (void *)rd_buff + record_size > rd_len)
break;

/* check for second-stage data integration */
if (record->checksum2 != get_cache_record_checksum2(record)) {
fprintf(stderr, "error: cache record data corrupted\n");
fprintf(stderr, "ERROR: Cache record data corrupted\n");
goto return_failure;
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void cmusfm_cache_submit(scrobbler_session_t *sbs) {
}
#endif

debug("cache: %s - %s (%s) - %d. %s (%ds)",
debug("Cache: %s - %s (%s) - %d. %s (%ds)",
sb_tinf.artist, sb_tinf.album, sb_tinf.album_artist,
sb_tinf.track_number, sb_tinf.track, sb_tinf.duration);

Expand Down
28 changes: 14 additions & 14 deletions src/libscrobbler2.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* libscrobbler2.c
* Copyright (c) 2011-2017 Arkadiusz Bokowy
* Copyright (c) 2011-2018 Arkadiusz Bokowy
*
* This file is a part of cmusfm.
*
Expand Down Expand Up @@ -54,7 +54,7 @@ static size_t sb_curl_write_callback(char *ptr, size_t size, size_t nmemb,
struct sb_response_data *rd = (struct sb_response_data *)data;
size *= nmemb;

debug("read: size: %zu, body: %s", size, ptr);
debug("Read: size: %zu, body: %s", size, ptr);

/* XXX: Passing a zero bytes data to this callback is not en error,
* however memory allocation fail is. */
Expand Down Expand Up @@ -111,7 +111,7 @@ static void sb_curl_cleanup(CURL *curl, struct sb_response_data *response) {
static scrobbler_status_t sb_check_response(struct sb_response_data *response,
int curl_status, scrobbler_session_t *sbs) {

debug("check: status: %d, body: %s", curl_status, response->data);
debug("Check: status: %d, body: %s", curl_status, response->data);

/* network transfer failure (curl error) */
if (curl_status != 0) {
Expand Down Expand Up @@ -160,7 +160,7 @@ static void sb_generate_method_signature(struct sb_getpost_data *sb_data,
offset += sprintf(tmp_str + offset, format, sb_data[x].name, sb_data[x].data);
}

debug("signature data: %s", tmp_str);
debug("Signature data: %s", tmp_str);
strcat(tmp_str, secret_hex);
MD5((unsigned char *)tmp_str, strlen(tmp_str), sign);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ static char *sb_make_curl_getpost_string(CURL *curl, char *str_buffer,

/* strip '&' from the end of the string */
str_buffer[offset - 1] = 0;
debug("params: %s", str_buffer);
debug("Params: %s", str_buffer);

return str_buffer;
}
Expand Down Expand Up @@ -229,8 +229,8 @@ scrobbler_status_t scrobbler_scrobble(scrobbler_session_t *sbs,
{"api_sig", 's', sign_hex},
};

debug("scrobble: %ld", sbt->timestamp);
debug("payload: %s - %s (%s) - %d. %s (%ds)",
debug("Scrobble: %ld", sbt->timestamp);
debug("Payload: %s - %s (%s) - %d. %s (%ds)",
sbt->artist, sbt->album, sbt->album_artist,
sbt->track_number, sbt->track, sbt->duration);

Expand All @@ -252,7 +252,7 @@ scrobbler_status_t scrobbler_scrobble(scrobbler_session_t *sbs,
curl_easy_setopt(curl, CURLOPT_URL, sbs->api_url);

sb_check_response(&response, curl_easy_perform(curl), sbs);
debug("scrobble status: %d", sbs->status);
debug("Scrobble status: %d", sbs->status);

sb_curl_cleanup(curl, &response);
return sbs->status;
Expand Down Expand Up @@ -286,8 +286,8 @@ static scrobbler_status_t sb_update_now_playing(scrobbler_session_t *sbs,
{"api_sig", 's', sign_hex},
};

debug("now playing: %ld", sbt->timestamp);
debug("payload: %s - %s (%s) - %d. %s (%ds)",
debug("Now playing: %ld", sbt->timestamp);
debug("Payload: %s - %s (%s) - %d. %s (%ds)",
sbt->artist, sbt->album, sbt->album_artist,
sbt->track_number, sbt->track, sbt->duration);

Expand All @@ -306,7 +306,7 @@ static scrobbler_status_t sb_update_now_playing(scrobbler_session_t *sbs,
curl_easy_setopt(curl, CURLOPT_URL, sbs->api_url);

sb_check_response(&response, curl_easy_perform(curl), sbs);
debug("now playing status: %d", sbs->status);
debug("Now playing status: %d", sbs->status);

sb_curl_cleanup(curl, &response);
return sbs->status;
Expand All @@ -315,7 +315,7 @@ static scrobbler_status_t sb_update_now_playing(scrobbler_session_t *sbs,
/* Update "Now playing" notification. */
scrobbler_status_t scrobbler_update_now_playing(scrobbler_session_t *sbs,
scrobbler_trackinfo_t *sbt) {
debug("now playing wrapper");
debug("Now playing wrapper");
if (sbt->artist == NULL || sbt->track == NULL)
return sbs->status = SCROBBLER_STATUS_ERR_TRACKINF;
return sb_update_now_playing(sbs, sbt);
Expand All @@ -324,7 +324,7 @@ scrobbler_status_t scrobbler_update_now_playing(scrobbler_session_t *sbs,
/* Hard-codded method for validating session key. This approach uses the
* updateNotify method call with invalid parameters as a test call. */
scrobbler_status_t scrobbler_test_session_key(scrobbler_session_t *sbs) {
debug("session validation wrapper");
debug("Session validation wrapper");
scrobbler_trackinfo_t sbt = { .artist = "", .track = "" };
return sb_update_now_playing(sbs, &sbt);
}
Expand Down Expand Up @@ -408,7 +408,7 @@ scrobbler_status_t scrobbler_authentication(scrobbler_session_t *sbs,
curl_easy_setopt(curl, CURLOPT_URL, get_url);

status = sb_check_response(&response, curl_easy_perform(curl), sbs);
debug("authentication status: %d", sbs->status);
debug("Authentication status: %d", sbs->status);
if (status != SCROBBLER_STATUS_OK) {
sb_curl_cleanup(curl, &response);
return status;
Expand Down
16 changes: 8 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* main.c
* Copyright (c) 2010-2017 Arkadiusz Bokowy
* Copyright (c) 2010-2018 Arkadiusz Bokowy
*
* This file is a part of cmusfm.
*
Expand Down Expand Up @@ -64,7 +64,7 @@ static struct cmtrack_info *get_track_info(int argc, char *argv[]) {
tinfo->status = CMSTATUS_UNDEFINED;

for (i = 1; i + 1 < argc; i += 2) {
debug("cmus argv: %s %s", argv[i], argv[i + 1]);
debug("Cmus argv: %s %s", argv[i], argv[i + 1]);
if (strcmp(argv[i], "status") == 0) {
if (strcmp(argv[i + 1], "playing") == 0)
tinfo->status = CMSTATUS_PLAYING;
Expand Down Expand Up @@ -166,13 +166,13 @@ static void cmusfm_spawn_server_process(const char *cmusfm) {
pid_t pid;

if ((pid = fork()) == -1) {
perror("error: fork server");
perror("ERROR: Fork server");
exit(EXIT_FAILURE);
}

if (pid == 0) {
execlp(cmusfm, cmusfm, "server", NULL);
perror("error: exec server");
perror("ERROR: Exec server");
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -202,7 +202,7 @@ int main(int argc, char *argv[]) {
}

if (cmusfm_config_read(cmusfm_config_file, &config) == -1) {
perror("error: config read");
perror("ERROR: Read config");
return EXIT_FAILURE;
}

Expand All @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) {

/* try to parse cmus status display program arguments */
if ((tinfo = get_track_info(argc, argv)) == NULL) {
perror("error: get track info");
perror("ERROR: Get track info");
return EXIT_FAILURE;
}

Expand All @@ -220,8 +220,8 @@ int main(int argc, char *argv[]) {
sleep(1);
}

if (cmusfm_server_send_track(tinfo)) {
fprintf(stderr, "error: sending track to server failed\n");
if (cmusfm_server_send_track(tinfo) != 0) {
perror("ERROR: Send track");
return EXIT_FAILURE;
}

Expand Down
4 changes: 2 additions & 2 deletions src/notify.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* notify.c
* Copyright (c) 2014-2017 Arkadiusz Bokowy
* Copyright (c) 2014-2018 Arkadiusz Bokowy
*
* This file is a part of cmusfm.
*
Expand Down Expand Up @@ -58,7 +58,7 @@ void cmusfm_notify_show(const scrobbler_trackinfo_t *sb_tinf, const char *icon)

cmus_notify = notify_notification_new(sb_tinf->track, body, icon);
if (!notify_notification_show(cmus_notify, &error)) {
debug("desktop notify error: %s", error->message);
debug("Desktop notify error: %s", error->message);
g_error_free(error);
/* NOTE: Free the notification subsystem upon show failure. This action
* allows us to recover from the D-Bus connection failure, which
Expand Down
Loading

0 comments on commit db5458b

Please sign in to comment.