fix for syntax measure
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c21439d94..e7b459dd9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495
 - Fix mismatching default value of parameter `ensure_ascii` https://github.com/Textualize/rich/pull/2538
 - Remove unused height parameter in `Layout` class https://github.com/Textualize/rich/pull/2540
+- Fixed exception in Syntax.__rich_measure__ for empty files
 
 
 ### Changed
diff --git a/rich/syntax.py b/rich/syntax.py
index 51f890ccb..aed041f34 100644
--- a/rich/syntax.py
+++ b/rich/syntax.py
@@ -593,10 +593,11 @@ def __rich_measure__(
         if self.code_width is not None:
             width = self.code_width + self._numbers_column_width + padding + 1
             return Measurement(self._numbers_column_width, width)
+        lines = self.code.splitlines()
         width = (
             self._numbers_column_width
             + padding
-            + max(cell_len(line) for line in self.code.splitlines())
+            + (max(cell_len(line) for line in lines) if lines else 0)
         )
         if self.line_numbers:
             width += 1
diff --git a/tests/test_syntax.py b/tests/test_syntax.py
index 6b8ce9ec1..5eff05eea 100644
--- a/tests/test_syntax.py
+++ b/tests/test_syntax.py
@@ -392,6 +392,9 @@ def test_syntax_measure():
     code = Syntax("Hello, World", "python", code_width=20, line_numbers=True)
     assert code.__rich_measure__(console, console.options) == Measurement(3, 24)
 
+    code = Syntax("", "python", code_width=20, line_numbers=True)
+    assert code.__rich_measure__(console, console.options) == Measurement(3, 24)
+
 
 if __name__ == "__main__":
     syntax = Panel.fit(

## Type of changes

- [ ] Bug fix
- [ ] New feature
- [ ] Documentation / docstrings
- [ ] Tests
- [ ] Other

## Checklist

- [ ] I've run the latest [black](https://github.com/psf/black) with default args on new code.
- [ ] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
- [ ] I've added tests for new code.
- [ ] I accept that @willmcgugan may be pedantic in the code review.

## Description

Please describe your changes here. If this fixes a bug, please link to the issue, if possible.
