Skip to content

Commit

Permalink
Merge pull request #938 from lwindolf/feed-error-info
Browse files Browse the repository at this point in the history
Fixes #809: Improved error presentation for feed fetch errors
  • Loading branch information
lwindolf authored Jan 10, 2021
2 parents ab78816 + 4339661 commit 2603ec6
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 304 deletions.
47 changes: 13 additions & 34 deletions css/liferea.css
Original file line number Diff line number Diff line change
Expand Up @@ -231,48 +231,33 @@ a.favicon img {
padding:0;
}

/* style for the HTTP error box at the beginning
/* style for the feed fetch error box at the beginning
of the feed description and for item comment feeds */
#errors, #commentFeedError {
width:100%;
#errors {
border:0;
border-bottom:1px solid black;
margin:0;
margin:12px 24px;
padding:12px;
background:#ffa;
color:black;
border:1px solid #GTK-COLOR-DARK;
}

#commentFeedError {
border:1px solid black;
#errors ul {
list-style-type: none;
padding-inline-start: 15px;
}

#parseError, #filterError, #updateError {
padding:2px;
padding-left:5px;
padding-right:5px;
#errors * li {
padding:1px;
}

div.xmlparseroutput {
margin:10px 0px 10px 15px;
pre.errorOutput {
margin:10px 15px;
padding:5px;
border:2px solid #GTK-COLOR-DARK;
background:#GTK-COLOR-LIGHT;
}

span.details, span.detaillink {
visibility:hidden;
display:none;
}

span.details {
padding:5px;
margin:15px;
}

span.showmore {
text-decoration:underline;
color:blue;
cursor:pointer;
overflow:auto;
}

del {
Expand All @@ -284,12 +269,6 @@ ins {
}

/* namespace specific styles */
div.blogchanneltitle {
padding-left:10px;
padding-right:10px;
background-color:#GTK-COLOR-DARK;
color:#GTK-COLOR-TEXT;
}

.slash {
background:#60A080;
Expand Down
12 changes: 3 additions & 9 deletions css/user.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,12 @@
// div.comment_body { }
// div.comment_title { }

/* Styles for the HTTP error box at the beginning
/* Styles for the feed fetch error box at the beginning
of the feed description and for item comment feeds */
// #errors, #commentFeedError { }
// #parseError, #filterError, #updateError { }
// div.xmlparseroutput { }
// span.details, span.detaillink { }
// span.details { }
// span.showmore { }
// #errors { }
// pre.errorOutput { }

/* namespace specific styles */
// div.blogchanneltitle { }
// div.photoheader { }

/* Gravatar embedding */
// img.gravatar { }
Expand Down
17 changes: 6 additions & 11 deletions src/comments.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,9 @@ comments_process_update_result (const struct updateResult * const result, gpoint

/* parse the new downloaded feed into fake node, subscription and feed */
node = node_new (feed_get_node_type ());
ctxt = feed_create_parser_ctxt ();
ctxt->subscription = subscription_new (result->source, NULL, NULL);
ctxt->feed = feed_new ();
node_set_data (node, ctxt->feed);
node_set_subscription (node, ctxt->subscription);
ctxt->data = result->data;
ctxt->dataLength = result->size;
node_set_data (node, feed_new ());
node_set_subscription (node, subscription_new (result->source, NULL, NULL));
ctxt = feed_parser_ctxt_new (node->subscription, result->data, result->size);

if (!feed_parse (ctxt)) {
debug0 (DEBUG_UPDATE, "parsing comment feed failed!");
Expand Down Expand Up @@ -159,16 +155,15 @@ comments_process_update_result (const struct updateResult * const result, gpoint
}

node_free (ctxt->subscription->node);
feed_free_parser_ctxt (ctxt);
feed_parser_ctxt_free (ctxt);
}

/* update error message */
g_free (commentFeed->error);
commentFeed->error = NULL;

if ((result->httpstatus < 200) || (result->httpstatus >= 400)) {
commentFeed->error = g_strdup (network_strerror (result->returncode, result->httpstatus));
}
if ((result->httpstatus < 200) || (result->httpstatus >= 400))
commentFeed->error = g_strdup (network_strerror (result->httpstatus));

/* clean up... */
commentFeed->updateJob = NULL;
Expand Down
88 changes: 43 additions & 45 deletions src/feed.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file feed.c feed node and subscription type
*
* Copyright (C) 2003-2020 Lars Windolf <[email protected]>
* Copyright (C) 2003-2021 Lars Windolf <[email protected]>
* Copyright (C) 2004-2006 Nathan J. Conrad <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -178,6 +178,10 @@ feed_add_xml_attributes (nodePtr node, xmlNodePtr feedNode)

if(feed->parseErrors && (strlen(feed->parseErrors->str) > 0))
xmlNewTextChild(feedNode, NULL, "parseError", feed->parseErrors->str);

tmp = g_strdup_printf("%d", node->subscription->error);
xmlNewTextChild(feedNode, NULL, "error", tmp);
g_free(tmp);
}

xmlDocPtr
Expand Down Expand Up @@ -297,7 +301,6 @@ feed_enrich_item (subscriptionPtr subscription, itemPtr item)
update_execute_request (subscription, request, feed_enrich_item_cb, GUINT_TO_POINTER (item->id), FEED_REQ_NO_FEED);
}


/* implementation of subscription type interface */

static void
Expand All @@ -310,53 +313,48 @@ feed_process_update_result (subscriptionPtr subscription, const struct updateRes

debug_enter ("feed_process_update_result");

if (result->data) {
/* parse the new downloaded feed into feed and itemSet */
ctxt = feed_create_parser_ctxt ();
ctxt->feed = feed;
ctxt->data = result->data;
ctxt->dataLength = result->size;
ctxt->subscription = subscription;

/* try to parse the feed */
if (!feed_parse (ctxt)) {
/* No feed found, display an error */
node->available = FALSE;

g_string_prepend (feed->parseErrors, _("<p>Could not detect the type of this feed! Please check if the source really points to a resource provided in one of the supported syndication formats!</p>"
"XML Parser Output:<br /><div class='xmlparseroutput'>"));
g_string_append (feed->parseErrors, "</div>");
} else if (!ctxt->feed->fhp) {
/* There's a feed but no handler. This means autodiscovery
* found a feed, but we still need to download it.
* An update should be in progress that will process it */
} else {
/* Feed found, process it */
itemSetPtr itemSet;

node->available = TRUE;

/* merge the resulting items into the node's item set */
itemSet = node_get_itemset (node);
node->newCount = itemset_merge_items (itemSet, ctxt->items, ctxt->feed->valid, ctxt->feed->markAsRead);
if (node->newCount)
itemlist_merge_itemset (itemSet);
itemset_free (itemSet);

/* restore user defined properties if necessary */
if ((flags & FEED_REQ_RESET_TITLE) && ctxt->title)
node_set_title (node, ctxt->title);

if (flags > 0)
db_subscription_update (subscription);
}
ctxt = feed_parser_ctxt_new (subscription, result->data, result->size);

feed_free_parser_ctxt (ctxt);
} else {
/* try to parse the feed */
if (!feed_parse (ctxt)) {
/* No feed found, display an error */
node->available = FALSE;

} else if (!ctxt->feed->fhp) {
/* There's a feed but no handler. This means autodiscovery
* found a feed, but we still need to download it.
* An update should be in progress that will process it */
} else {
/* Feed found, process it */
itemSetPtr itemSet;

node->available = TRUE;

/* merge the resulting items into the node's item set */
itemSet = node_get_itemset (node);
node->newCount = itemset_merge_items (itemSet, ctxt->items, ctxt->feed->valid, ctxt->feed->markAsRead);
if (node->newCount)
itemlist_merge_itemset (itemSet);
itemset_free (itemSet);

/* restore user defined properties if necessary */
if ((flags & FEED_REQ_RESET_TITLE) && ctxt->title)
node_set_title (node, ctxt->title);

// FIXME: this duplicates the db_subscription_update() in subscription.c
if (flags > 0)
db_subscription_update (subscription);
}

feed_list_view_update_node (node->id);
feed_parser_ctxt_free (ctxt);

// FIXME: this should not be here, but in subscription.c
if (FETCH_ERROR_NONE != subscription->error) {
node->available = FALSE;
liferea_shell_set_status_bar (_("\"%s\" is not available"), node_get_title (node));
} else {
liferea_shell_set_status_bar (_("\"%s\" updated..."), node_get_title (node));
}

debug_exit ("feed_process_update_result");
}
Expand Down
24 changes: 12 additions & 12 deletions src/feed.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @file feed.h common feed handling interface
*
* Copyright (C) 2003-2017 Lars Windolf <[email protected]>
*
* Copyright (C) 2003-2021 Lars Windolf <[email protected]>
* Copyright (C) 2004-2006 Nathan J. Conrad <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Expand All @@ -31,15 +31,15 @@
/*
* The feed concept in Liferea comprises several standalone concepts:
*
* 1.) A "feed" is an XML document to be parsed
* 1.) A "feed" is an XML/XML-like document to be parsed
* (-> see feed_parser.h)
*
* 2.) A "feed" is a node in the feed list.
* 2.) A "feed" is a node type that is visible in the feed list.
*
* 3.) A "feed" is a way of updating a subscription.
* 3.) A "feed" is a subscription type: a way of updating.
*
* The feed.h interface provides default methods for 2.) and 3.) that
* are used per-default but might be overwritten by node source, node
* The feed.h interface provides default methods for 2.) and 3.) that
* are used per-default but might be overwritten by node source, node
* type or subscription type specific implementations.
*/

Expand All @@ -49,10 +49,10 @@ typedef struct feed {

/* feed cache state properties */
gint cacheLimit; /**< Amount of cache to save: See the cache_limit enum */

/* feed parsing state */
gboolean valid; /**< FALSE if there was an error in xml_parse_feed() */
GString *parseErrors; /**< textual description of parsing errors */
GString *parseErrors; /**< Detailed textual description of parsing errors (e.g. library error handler output) */
gint64 time; /**< Feeds modified date */

/* feed specific behaviour settings */
Expand All @@ -76,15 +76,15 @@ feedPtr feed_new(void);
* @param feedNode XML node to add feed attributes to,
* or NULL if a new XML document is to
* be created
*
*
* @returns a new XML document (if feedNode was NULL)
*/
xmlDocPtr feed_to_xml(nodePtr node, xmlNodePtr xml);

// FIXME: doesn't seem to belong here (looks like a subscription type method)
/**
* Returns the feed-specific maximum cache size.
* If none is set it returns the global default
* If none is set it returns the global default
* setting.
*
* @param node the feed node
Expand Down
Loading

0 comments on commit 2603ec6

Please sign in to comment.