Skip to content

fix: replace bare except with except Exception in open_las#369

Open
AmSach wants to merge 1 commit into
laspy:masterfrom
AmSach:fix/bare-except-in-open-las
Open

fix: replace bare except with except Exception in open_las#369
AmSach wants to merge 1 commit into
laspy:masterfrom
AmSach:fix/bare-except-in-open-las

Conversation

@AmSach

@AmSach AmSach commented Jun 8, 2026

Copy link
Copy Markdown

Description

Replaces 3 bare except: clauses in laspy/lib.py's open_las() function with except Exception:.

Why

Bare except: clauses catch all exceptions, including BaseException-derived classes like KeyboardInterrupt and SystemExit. This can:

  1. Prevent clean program termination on Ctrl+C
  2. Catch exceptions that should propagate up to the interpreter
  3. Make the code's intent unclear (is it catching errors or signals?)

The intent of the existing code is clear: if the LasReader/LasWriter/LasAppender constructor fails, close the stream and re-raise. This is application-level error handling, so Exception is the right base class.

Pattern Consistency

This also matches the existing pattern used throughout the codebase:

  • laspy/lasreader.py: except Exception as e:
  • laspy/laswriter.py: except Exception as e:
  • laspy/lasappender.py: except Exception as e:

Diff

-        except:
+        except Exception:
             if closefd:
                 stream.close()
             raise

(3 occurrences, in the r, w, and a mode branches)

— Sent via @AmSach bot

Bare except clauses catch all exceptions including BaseException-derived
classes like KeyboardInterrupt and SystemExit, which can prevent clean
program termination. Replacing with 'except Exception' makes the intent
explicit (catch application errors only) and matches the pattern used
elsewhere in the codebase (lasreader.py, laswriter.py, lasappender.py).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant