{"record":{"id":"07275db2de396aaa","repo":"TheAlgorithms/Python","slug":"invalid-source-or-destination-coordinates","errorCode":null,"errorMessage":"Invalid source or destination coordinates","messagePattern":"Invalid source or destination coordinates","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backtracking/rat_in_maze.py","lineNumber":127,"sourceCode":"    >>> solve_maze(maze,2,0,len(maze)-1,len(maze)-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Invalid source or destination coordinates\n\n    >>> maze = [[1, 0, 0],\n    ...         [0, 1, 0],\n    ...         [1, 0, 0]]\n    >>> solve_maze(maze,0,1,len(maze),len(maze)-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Invalid source or destination coordinates\n    \"\"\"\n    size = len(maze)\n    # Check if source and destination coordinates are Invalid.\n    if not (0 <= source_row <= size - 1 and 0 <= source_column <= size - 1) or (\n        not (0 <= destination_row <= size - 1 and 0 <= destination_column <= size - 1)\n    ):\n        raise ValueError(\"Invalid source or destination coordinates\")\n    # We need to create solution object to save path.\n    solutions = [[1 for _ in range(size)] for _ in range(size)]\n    solved = run_maze(\n        maze, source_row, source_column, destination_row, destination_column, solutions\n    )\n    if solved:\n        return solutions\n    else:\n        raise ValueError(\"No solution exists!\")\n\n\ndef run_maze(\n    maze: list[list[int]],\n    i: int,\n    j: int,\n    destination_row: int,\n    destination_column: int,\n    solutions: list[list[int]],","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/backtracking/rat_in_maze.py#L109-L145","documentation":"Raised by center_of_mass() in physics/center_of_mass.py when any particle in the list has mass <= 0 (zero or negative). A zero-mass particle contributes nothing but still passes the emptiness check, and negative masses make the weighted average meaningless; total_mass could even become 0 and cause a ZeroDivisionError, so the library rejects them up front.","triggerScenarios":"center_of_mass([Particle(0, 0, 0, 0)]); any list containing a Particle whose mass field is 0 or negative, e.g. Particle(9, 10, 11, 0) or Particle(1, 2, 3, -5).","commonSituations":"Field-order mistakes when constructing Particle(x, y, z, mass) — putting mass in the wrong slot; imported data with missing masses defaulted to 0; placeholder particles added with mass 0.","solutions":["Verify Particle field order is (x, y, z, mass) at every construction site.","Filter or repair particles before the call: [p for p in particles if p.mass > 0].","Treat mass<=0 rows in source data as corrupt and log/skip them."],"exampleFix":"# before\ncom = center_of_mass(all_particles)  # some have mass 0\n\n# after\nvalid = [p for p in all_particles if p.mass > 0]\ncom = center_of_mass(valid) if valid else None","handlingStrategy":"validation","validationCode":"valid = [p for p in particles if p.mass > 0]\nif not valid:\n    raise ValueError(\"no particles with positive mass\")\ncom = center_of_mass(valid)","typeGuard":"from collections import namedtuple\nParticle = namedtuple('Particle', 'x y z mass')\ndef has_valid_masses(ps: list) -> bool:\n    return all(p.mass > 0 for p in ps)","tryCatchPattern":"try:\n    com = center_of_mass(particles)\nexcept ValueError as e:\n    if \"Mass\" in str(e):\n        bad = [i for i, p in enumerate(particles) if p.mass <= 0]\n        raise ValueError(f\"non-positive mass at indices {bad}\") from e\n    raise","preventionTips":["Particle field order is (x, y, z, mass) — enforce with keywords: Particle(x=.., y=.., z=.., mass=..).","Reject mass<=0 rows at data ingest.","Remember 0 mass is also rejected here (unlike centripetal)."],"tags":["physics","input-validation","data-quality"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}