Bug 111133 - Long URLs in error messages should be shortened
Summary: Long URLs in error messages should be shortened
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mike West
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-28 17:48 PST by Eric Seidel (no email)
Modified: 2013-03-07 02:29 PST (History)
5 users (show)

See Also:


Attachments
Patch (4.00 KB, patch)
2013-03-01 02:50 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (28.68 KB, patch)
2013-03-02 12:34 PST, Mike West
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2013-02-28 17:48:26 PST
Long URLs in error messages should be shortened

.... (10MB of data)....
XVpLTMiPjwvbGk+Ci0tPgoKIAo=' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

I'm sure we have lots of these. :(  I suspect this is affecting performance of some of our data: url tests (including perf tests).
Comment 1 Mike West 2013-03-01 02:01:05 PST
We're already visually shortening the messages in the console. I don't see any reason that we couldn't shorten the actual string when it's over some arbitrarily large limit. We'd lose the ability to click through to see the page that generated the error, but for this specific case that's probably not a terrible loss.

1. Can you point me at a test result that's currently shockingly large?
2. What's the most performant mechanism to shorten a string? :)
Comment 2 Eric Seidel (no email) 2013-03-01 02:13:36 PST
Oh, the log that I'm seeing is not on the console, it's to stdout/stderr. :)  I see this when running DRT manually.
Comment 3 Mike West 2013-03-01 02:21:03 PST
Right, we don't shorten the string at all, we just look for URLs and elide them when they're over some length (~150 characters, I think). It's perfectly reasonable to do that at the string level for some higher limit (1k?). I'll throw up a patch as soon as I remember how to export methods from KURL for use in WebCore. :/
Comment 4 Mike West 2013-03-01 02:23:12 PST
(In reply to comment #3)
> I'll throw up a patch as soon as I remember how to export methods from KURL for use in WebCore. :/

Scratch that. I'll upload a patch as soon as I realize that I'm an idiot who can't properly read linker errors. :)
Comment 5 Eric Seidel (no email) 2013-03-01 02:28:15 PST
I think we need to do a somewhat careful audit of all the times we're copying (see bug 111134) or converting urls to strings.  URLs can literally be megabytes in length in WebKit.  :)
Comment 6 Eric Seidel (no email) 2013-03-01 02:28:35 PST
(I'm not suggesting we need to do such as part of this bug.  More just complaining in public.)
Comment 7 Mike West 2013-03-01 02:50:12 PST
Created attachment 190916 [details]
Patch
Comment 8 Mike West 2013-03-01 02:51:29 PST
(In reply to comment #7)
> Created an attachment (id=190916) [details]
> Patch

Feedback welcome, Eric and Pavel. If this seems like a workable approach, I'll go through the rest of the console messages that contain URLs and add them to the patch.

I'm a bit worried about the substring and concat approach in terms of performance. I'd appreciate alternative suggestions.
Comment 9 Eric Seidel (no email) 2013-03-01 02:52:58 PST
Comment on attachment 190916 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=190916&action=review

> Source/WebCore/bindings/ScriptControllerBase.cpp:45
> +            m_frame->document()->addConsoleMessage(HTMLMessageSource, ErrorMessageLevel, "Blocked script execution in '" + m_frame->document()->url().elidedString() + "' because the document's frame is sandboxed and the 'allow-scripts' permission is not set."); 

I wonder if we should be ASSERTing in addConsoleMessage for certain error levels that we're not above a certain size threshold.
Comment 10 Eric Seidel (no email) 2013-03-01 02:53:21 PST
Going to leave this for abarth or pfeldman to review.  I'm a bit too tired to be a good reviewer right now. :)
Comment 11 Mike West 2013-03-01 02:56:40 PST
(In reply to comment #9)
> (From update of attachment 190916 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=190916&action=review
> 
> > Source/WebCore/bindings/ScriptControllerBase.cpp:45
> > +            m_frame->document()->addConsoleMessage(HTMLMessageSource, ErrorMessageLevel, "Blocked script execution in '" + m_frame->document()->url().elidedString() + "' because the document's frame is sandboxed and the 'allow-scripts' permission is not set."); 
> 
> I wonder if we should be ASSERTing in addConsoleMessage for certain error levels that we're not above a certain size threshold.

That probably makes sense for some reasonably high amount. 10k? 100k?

Pavel will certainly have opinions here. :)
Comment 12 Mike West 2013-03-01 02:58:35 PST
Jochen expressed some doubt about putting this on KURL. Adding him in case his doubt grows into an r-.
Comment 13 Adam Barth 2013-03-01 10:00:12 PST
Comment on attachment 190916 [details]
Patch

LGTM, but I'll give jochen and others a chance to comment.
Comment 14 jochen 2013-03-01 12:48:06 PST
Comment on attachment 190916 [details]
Patch

ok
Comment 15 jochen 2013-03-01 12:50:03 PST
(In reply to comment #12)
> Jochen expressed some doubt about putting this on KURL. Adding him in case his doubt grows into an r-.

I thought you were talking about a case where the inspector is passed the URL. But you're passing a string, so you'll have to do the conversion earlier, so it's ok
Comment 16 Mike West 2013-03-02 12:12:32 PST
(In reply to comment #15)
> (In reply to comment #12)
> > Jochen expressed some doubt about putting this on KURL. Adding him in case his doubt grows into an r-.
> 
> I thought you were talking about a case where the inspector is passed the URL. But you're passing a string, so you'll have to do the conversion earlier, so it's ok

Cool. I'll add a few of the more obvious cases of copying full, potentially long URLs and land this on Monday.

We can take a closer look at the non-obvious bits in bug 111134.
Comment 17 Mike West 2013-03-02 12:34:32 PST
Created attachment 191115 [details]
Patch
Comment 18 Mike West 2013-03-02 12:35:24 PST
Comment on attachment 191115 [details]
Patch

Clearing r?, carrying over Jochen's r+. I'll wait until Monday to land this.
Comment 19 WebKit Review Bot 2013-03-04 01:35:48 PST
Comment on attachment 191115 [details]
Patch

Clearing flags on attachment: 191115

Committed r144607: <http://trac.webkit.org/changeset/144607>
Comment 20 WebKit Review Bot 2013-03-04 01:35:52 PST
All reviewed patches have been landed.  Closing bug.
Comment 21 Darin Adler 2013-03-04 14:31:18 PST
Comment on attachment 191115 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=191115&action=review

> Source/WebCore/ChangeLog:28
> +        * platform/KURL.cpp:
> +        (WebCore::KURL::elidedString): Added.
> +        * platform/KURL.h:
> +            An exciting new method that gives you the same result as string()
> +            for URLs less than 1k long, and elides the middle of URLs longer
> +            than 1k by replacing everything but the first and last 0.5k with
> +            "...".

The name “elided string” does not seem good for this function.

It’s nice that it’s a short name. But the string is not “elided”, only the middle of the string is.
Comment 22 Mike West 2013-03-04 14:46:51 PST
(In reply to comment #21)
> (From update of attachment 191115 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=191115&action=review
> 
> > Source/WebCore/ChangeLog:28
> > +        * platform/KURL.cpp:
> > +        (WebCore::KURL::elidedString): Added.
> > +        * platform/KURL.h:
> > +            An exciting new method that gives you the same result as string()
> > +            for URLs less than 1k long, and elides the middle of URLs longer
> > +            than 1k by replacing everything but the first and last 0.5k with
> > +            "...".
> 
> The name “elided string” does not seem good for this function.
> 
> It’s nice that it’s a short name. But the string is not “elided”, only the middle of the string is.

Hrm. I thought the name fit well conceptually, but I'm happy to change it for clarity.

"ellipsisedString"? I'm not sure "ellipsised" is a word. :) "stringTrimmedTo1k"? It looks like DevTools has a 'trimMiddle' function[1], perhaps following that convention would be reasonable?

[1]: http://trac.webkit.org/browser/trunk/Source/WebCore/inspector/front-end/utilities.js#L117
Comment 23 Mike West 2013-03-07 02:29:32 PST
Split out renaming into https://bugs.webkit.org/show_bug.cgi?id=111700.