WantNotValidException.java

  1. /*
  2.  * Copyright (C) 2016, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.transport;

  11. import java.text.MessageFormat;

  12. import org.eclipse.jgit.errors.PackProtocolException;
  13. import org.eclipse.jgit.internal.JGitText;
  14. import org.eclipse.jgit.lib.AnyObjectId;

  15. /**
  16.  * Indicates client requested an object the server does not want to serve.
  17.  * <p>
  18.  * Typically visible only inside of the server implementation; clients are
  19.  * usually looking at the text message from the server in a generic
  20.  * {@link org.eclipse.jgit.errors.PackProtocolException}.
  21.  *
  22.  * @since 4.3
  23.  */
  24. public class WantNotValidException extends PackProtocolException {
  25.     private static final long serialVersionUID = 1L;

  26.     /**
  27.      * Construct a {@code "want $id not valid"} exception.
  28.      *
  29.      * @param id
  30.      *            invalid object identifier received from the client.
  31.      */
  32.     public WantNotValidException(AnyObjectId id) {
  33.         super(msg(id));
  34.     }

  35.     /**
  36.      * Construct a {@code "want $id not valid"} exception.
  37.      *
  38.      * @param id
  39.      *            invalid object identifier received from the client.
  40.      * @param cause
  41.      *            root cause of the object being invalid, such as an IOException
  42.      *            from the storage system.
  43.      */
  44.     public WantNotValidException(AnyObjectId id, Throwable cause) {
  45.         super(msg(id), cause);
  46.     }

  47.     private static String msg(AnyObjectId id) {
  48.         return MessageFormat.format(JGitText.get().wantNotValid, id.name());
  49.     }
  50. }