]> source.dussan.org Git - gitblit.git/commitdiff
Report identified user and command on command failure
authorDavid Ostrovsky <david@ostrovsky.org>
Wed, 19 Mar 2014 20:43:41 +0000 (21:43 +0100)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 22:58:09 +0000 (18:58 -0400)
Fix commented out code. Now failure is reported as:

  Internal server error (user admin) during gitblit version

src/main/java/com/gitblit/transport/ssh/commands/BaseCommand.java

index 4162a400c97ecfc743bd333fc16b29a23dbb4784..c4d6a57eaa14173057e6b9ca0b1401feed865b8c 100644 (file)
@@ -232,7 +232,7 @@ public abstract class BaseCommand implements Command, SessionAware {
                public void cancel() {
                        synchronized (this) {
                                try {
-                                       // onExit(/*STATUS_CANCEL*/);
+                                       onExit(STATUS_CANCEL);
                                } finally {
                                        ctx = null;
                                }
@@ -317,18 +317,12 @@ public abstract class BaseCommand implements Command, SessionAware {
        /**
         * Terminate this command and return a result code to the remote client.
         * <p>
-        * Commands should invoke this at most once. Once invoked, the command may
-        * lose access to request based resources as any callbacks previously
-        * registered with {@link RequestCleanup} will fire.
+        * Commands should invoke this at most once.
         *
-        * @param rc
-        *            exit code for the remote client.
+        * @param rc exit code for the remote client.
         */
        protected void onExit(final int rc) {
                exit.onExit(rc);
-               // if (cleanup != null) {
-               // cleanup.run();
-               // }
        }
 
        private int handleError(final Throwable e) {
@@ -346,16 +340,14 @@ public abstract class BaseCommand implements Command, SessionAware {
                } else {
                        final StringBuilder m = new StringBuilder();
                        m.append("Internal server error");
-                       // if (userProvider.get().isIdentifiedUser()) {
-                       // final IdentifiedUser u = (IdentifiedUser) userProvider.get();
-                       // m.append(" (user ");
-                       // m.append(u.getAccount().getUserName());
-                       // m.append(" account ");
-                       // m.append(u.getAccountId());
-                       // m.append(")");
-                       // }
-                       // m.append(" during ");
-                       // m.append(contextProvider.get().getCommandLine());
+                       String user = ctx.getClient().getUsername();
+                       if (user != null) {
+                               m.append(" (user ");
+                               m.append(user);
+                               m.append(")");
+                       }
+                       m.append(" during ");
+                       m.append(ctx.getCommandLine());
                        log.error(m.toString(), e);
                }