• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None
    • Platform: All, OS: All

      When nextBuild/previousBuild links are clicked on a page that doesn't have the
      corresponding item in the next build (say a test report), it gives you 404.

      It should instead give you a custom error page that let people keep navigating
      without losing the context.

          [JENKINS-117] "nextBuild" link shouldn't give 404

          Alan Harder added a comment -

          This could be implemented to automatically jump back up to the build page..

          Index: core/src/main/java/hudson/model/Run.java
          ===================================================================
          — core/src/main/java/hudson/model/Run.java (revision 14038)
          +++ core/src/main/java/hudson/model/Run.java (working copy)
          @@ -1271,4 +1271,12 @@
          return Mailer.DESCRIPTOR.getAdminAddress();
          }
          }
          +
          + @Override
          + public Object getDynamic(String token, StaplerRequest req, StaplerResponse
          rsp) throws IOExcept
          ion

          { + Object result = super.getDynamic(token, req, rsp); + if (result == null) + rsp.sendRedirect(".."); + return result; + }

          }

          Then /job/Abc/123/someReport will automatically go to /job/Abc/123 if that build
          doesn't have "someReport". How does this sound?

          Note: I put "throws IOException" in the code above.. to use that, I'd also need
          to add throws IOException in the parent Actionable.getDynamic, and in several
          other classes that override this method and call super. Let me know if you'd
          prefer I just catch/ignore IOException in Run.getDynamic.

          Looking for a response before I commit or rework this one.. thanks.

          Alan Harder added a comment - This could be implemented to automatically jump back up to the build page.. Index: core/src/main/java/hudson/model/Run.java =================================================================== — core/src/main/java/hudson/model/Run.java (revision 14038) +++ core/src/main/java/hudson/model/Run.java (working copy) @@ -1271,4 +1271,12 @@ return Mailer.DESCRIPTOR.getAdminAddress(); } } + + @Override + public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) throws IOExcept ion { + Object result = super.getDynamic(token, req, rsp); + if (result == null) + rsp.sendRedirect(".."); + return result; + } } Then /job/Abc/123/someReport will automatically go to /job/Abc/123 if that build doesn't have "someReport". How does this sound? Note: I put "throws IOException" in the code above.. to use that, I'd also need to add throws IOException in the parent Actionable.getDynamic, and in several other classes that override this method and call super. Let me know if you'd prefer I just catch/ignore IOException in Run.getDynamic. Looking for a response before I commit or rework this one.. thanks.

          Alan Harder added a comment -

          Nevermind on "Note" above.. I found that while that code worked, it left
          exceptions in the console.. stapler still tried to send a 404 (since I return
          null) even though I already sent a redirect.. better way:

          Index: core/src/main/java/hudson/model/Run.java
          ===================================================================
          — core/src/main/java/hudson/model/Run.java (revision 14038)
          +++ core/src/main/java/hudson/model/Run.java (working copy)
          @@ -1271,4 +1271,21 @@
          return Mailer.DESCRIPTOR.getAdminAddress();
          }
          }
          +
          + @Override
          + public Object getDynamic(String token, StaplerRequest req, StaplerResponse
          rsp)

          { + Object result = super.getDynamic(token, req, rsp); + if (result == null) + // Next/Previous Build links on an action page (like /job/Abc/123/testReport) + // will also point to same action (/job/Abc/124/testReport), but other builds + // may not have the action.. rather than 404, redirect up to the build page. + result = new RedirectUp(); + return result; + }

          +
          + public static class RedirectUp {
          + public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws
          IOException

          { + rsp.sendRedirect(".."); + }

          + }
          }

          I'm going to go ahead and commit this.. let me know if you think it needs any
          rework.

          Alan Harder added a comment - Nevermind on "Note" above.. I found that while that code worked, it left exceptions in the console.. stapler still tried to send a 404 (since I return null) even though I already sent a redirect.. better way: Index: core/src/main/java/hudson/model/Run.java =================================================================== — core/src/main/java/hudson/model/Run.java (revision 14038) +++ core/src/main/java/hudson/model/Run.java (working copy) @@ -1271,4 +1271,21 @@ return Mailer.DESCRIPTOR.getAdminAddress(); } } + + @Override + public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) { + Object result = super.getDynamic(token, req, rsp); + if (result == null) + // Next/Previous Build links on an action page (like /job/Abc/123/testReport) + // will also point to same action (/job/Abc/124/testReport), but other builds + // may not have the action.. rather than 404, redirect up to the build page. + result = new RedirectUp(); + return result; + } + + public static class RedirectUp { + public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException { + rsp.sendRedirect(".."); + } + } } I'm going to go ahead and commit this.. let me know if you think it needs any rework.

          Code changed in hudson
          User: : mindless
          Path:
          trunk/hudson/main/core/src/main/java/hudson/model/Run.java
          http://fisheye4.cenqua.com/changelog/hudson/?cs=14099
          Log:
          [FIXED JENKINS-117] If next/previousBuild link jumps to an action not present
          in that build (like testReport) then redirect up to the build page.

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : mindless Path: trunk/hudson/main/core/src/main/java/hudson/model/Run.java http://fisheye4.cenqua.com/changelog/hudson/?cs=14099 Log: [FIXED JENKINS-117] If next/previousBuild link jumps to an action not present in that build (like testReport) then redirect up to the build page.

          Code changed in hudson
          User: : mindless
          Path:
          trunk/hudson/main/core/src/main/java/hudson/model/Run.java
          http://fisheye4.cenqua.com/changelog/hudson/?cs=14178
          Log:
          update to r14099 / JENKINS-117.
          Rather than directly sendRedirect, send a 404 response (this is accurate for requested URL)
          but include html with javascript/meta to redirect browsers up to build page.

          SCM/JIRA link daemon added a comment - Code changed in hudson User: : mindless Path: trunk/hudson/main/core/src/main/java/hudson/model/Run.java http://fisheye4.cenqua.com/changelog/hudson/?cs=14178 Log: update to r14099 / JENKINS-117 . Rather than directly sendRedirect, send a 404 response (this is accurate for requested URL) but include html with javascript/meta to redirect browsers up to build page.

            mindless Alan Harder
            kohsuke Kohsuke Kawaguchi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: