Shuffleboard Tab's 'Add' Function Throws Error if Title Is Already In Use (Rather than updating it)

When the add method is called on a Shuffleboard tab multiple times with the same title, it throws an error that terminates the program.

In WPILib’s documentation, it states that:


Sending simple data (numbers, strings, booleans, and arrays of these) is done by calling add on a tab. This method will set the value if not already present, but will not overwrite an existing value.

(See: Sending data — FIRST Robotics Competition documentation)


Thus, it should simply overwrite the data rather than throwing an error. An example of this:

package frc.robot;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab;

public class Robot extends TimedRobot {

  @Override
  public void robotInit() {
    ShuffleboardTab tab = Shuffleboard.getTab("Example Tab");

    tab.add("Example 1", 0.0);
    tab.add("Example 1", 1.0); // This throws the error!
  }
}

Rather than changing the value like it says in the documentation, it errors. stops the program.

The error thrown:

Error at frc.robot.Robot.robotInit(Robot.java:14): Unhandled exception: java.lang.IllegalArgumentException: Title is already in use: Example 1
        at edu.wpi.first.wpilibj.shuffleboard.ContainerHelper.checkTitle(ContainerHelper.java:139)
        at edu.wpi.first.wpilibj.shuffleboard.ContainerHelper.add(ContainerHelper.java:73)
        at edu.wpi.first.wpilibj.shuffleboard.ShuffleboardTab.add(ShuffleboardTab.java:66)
        at frc.robot.Robot.robotInit(Robot.java:14)
        at edu.wpi.first.wpilibj.TimedRobot.startCompetition(TimedRobot.java:107)
        at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:373)
        at edu.wpi.first.wpilibj.RobotBase.lambda$startRobot$0(RobotBase.java:443)
        at java.base/java.lang.Thread.run(Thread.java:833)

Warning at edu.wpi.first.wpilibj.RobotBase.runRobot(RobotBase.java:388): The robot program quit unexpectedly. This is usually due to a code error.
  The above stacktrace can help determine where the error occurred.
  See https://wpilib.org/stacktrace for more information.

The program builds successfully, but errors when the code runs. I am currently running this in a simulator, not on a physical RoboRio.

Am I doing something wrong, or is this an error with WPILib?

It says it will not overwrite an existing value. So if there is already a value, it throws. The way to update the value is to take the object returned from add, and update using that object.

Having an API called add behave in this way is standard Java practice. Theres usually another way to explicitly update values. In our case, we’ve chosen to use the returned object to handle that.

1 Like

:upside_down_face: oops, I read it wrong. Sorry.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.