alibaba/spring-ai-alibaba · warning · ResponseStatusException

graphName cannot be null or empty

Error message

graphName cannot be null or empty

What it means

GraphController.getGraphRepresentation validates the {graphName} path variable and throws a 400 BAD_REQUEST ResponseStatusException when it is null or blank before attempting to load the graph. In practice the path variable can only be blank when an empty path segment is requested.

Solutions

  1. Ensure the client passes a real graph name in the URL path.
  2. Trim/validate graphName client-side before building the URL.
  3. List available graphs first (graphLoader.listGraphs()) and pick a valid one.

Example fix

// before
fetch(`/graphs/${graphName}/representation`);
// after
if (!graphName?.trim()) throw new Error('graphName required');
fetch(`/graphs/${encodeURIComponent(graphName)}/representation`);
Defensive patterns

Strategy: validation

Validate before calling

// client-side, before the request
if (typeof graphName !== 'string' || !graphName.trim()) {
  throw new Error('graphName is required');
}

Type guard

function hasGraphName(p) {
  return typeof p.graphName === 'string' && p.graphName.trim().length > 0;
}

Try / catch

try {
  const res = await fetch(`/graphs/${encodeURIComponent(graphName)}/representation`);
  if (!res.ok) throw new Error(res.status + ' ' + (await res.text()));
} catch (e) {
  if (e.message.startsWith('400')) { /* fix graphName param */ }
}

Prevention

When it happens

Trigger: GET /graphs/{graphName}/representation with an empty/whitespace graphName path segment (e.g. /graphs/%20/representation).

Common situations: Client templates with an unfilled graphName variable producing an empty segment; URL-encoded whitespace; proxies stripping path segments.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/0a5f85e8d8313e05. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-studio/src/main/java/com/alibaba/cloud/ai/agent/studio/controller/GraphController.java:75

	 * @return A list of graph names.
	 */
	@GetMapping("/list-graphs")
	public List<String> listGraphs() {
		List<String> graphNames = graphLoader.listGraphs();
		log.debug("Listing graphs. Found: {}", graphNames);
		return graphNames.stream().sorted().collect(toList());
	}

	/**
	 * Returns the graph representation (Mermaid format) for the given graph name.
	 *
	 * @param graphName The name of the graph.
	 * @return GraphResponse containing the Mermaid diagram source.
	 */
	@GetMapping("/graphs/{graphName}/representation")
	public GraphResponse getGraphRepresentation(@PathVariable String graphName) {
		if (graphName == null || graphName.isBlank()) {
			throw new ResponseStatusException(org.springframework.http.HttpStatus.BAD_REQUEST,
					"graphName cannot be null or empty");
		}
		try {
			CompiledGraph graph = graphLoader.loadGraph(graphName);
			String title = graph.stateGraph != null ? graph.stateGraph.getName() : graphName;
			GraphRepresentation repr = graph.getGraph(GraphRepresentation.Type.MERMAID, title);
			return new GraphResponse(repr.content(), true);
		}
		catch (Exception e) {
			log.warn("Failed to get graph representation for: {}", graphName, e);
			throw new ResponseStatusException(org.springframework.http.HttpStatus.NOT_FOUND,
					"Graph not found: " + graphName, e);
		}
	}
}

View on GitHub (pinned to f82da0b50f)