Skip to content

Signal unreadable document dimensions in document/info and open_document - #92

Merged
loonghao merged 1 commit into
mainfrom
task/document-info-open-document-f587ce819bb1
Oct 14, 2026
Merged

loonghao merged 1 commit into
mainfrom
task/document-info-open-document-f587ce819bb1

Conversation

@loonghao

Copy link
Copy Markdown
Owner

Problem

Document.width / Document.height are read through to_float(), which collapses any
unconvertible value into its default (0.0) and only leaves a logger.warning. A client
therefore cannot distinguish a document that is genuinely zero-sized from one whose
dimensions Photoshop never reported — the symptom reported in issue #55 stayed invisible
rather than fixed.

Change

  • Added try_float() next to to_float(). It applies the same conversion rules but returns
    an UNCONVERTIBLE sentinel instead of a stand-in number, so callers can tell a real 0.0
    apart from an unreadable measurement. The warning log is kept.
  • photoshop://document/info and the photoshop_open_document tool now use try_float().
    When either dimension is unreadable, the payload gains dimensions_unavailable: true
    while width/height remain numeric (0.0).
  • to_float() and the create_document call site are unchanged.

Payload contract

This is an additive, non-breaking change. The new field is only present when dimensions
cannot be read, so consumers that ignore unknown keys see the exact same payload shape as
before. Existing fields (name, width, height, resolution, layers_count,
success, document_name) are never removed or renamed.

// dimensions unreadable
{"name": "a.psd", "width": 0.0, "height": 0.0, "resolution": 72, "layers_count": 0, "dimensions_unavailable": true}

// dimensions readable — field absent
{"name": "a.psd", "width": 1920.0, "height": 1080.0, "resolution": 72, "layers_count": 0}

Tests

Extended tests/unit/test_dimension_utils.py, reusing the existing host-free fakes:
try_float behaviour (including that a genuine 0 is not the sentinel); both branches for
the photoshop://document/info resource and the photoshop_open_document tool; readable
values as plain float and as UnitValue; unreadable values as opaque objects, None, and a
UnitValue with a non-numeric .value; and a genuine zero that must stay unflagged.

Verified with pytest tests/unit -q.

Note

tests/unit/test_stdio_log_pollution.py::test_stdio_session_stdout_is_pure_jsonrpc is
intermittently flaky on this machine independent of this change — it fails roughly 1 run in
8 on an unmodified main checkout, since it asserts on the output of a subprocess session.
Reproduced before touching any code; not addressed here.

…_document

When Photoshop does not report a document's width/height, both the
`photoshop://document/info` resource and the `photoshop_open_document`
tool silently collapsed them to 0.0, leaving clients unable to tell a
genuine zero apart from an unreadable measurement.

Add a `try_float` helper alongside `to_float` that returns an
UNCONVERTIBLE sentinel instead of a stand-in number, and use it at the
two call sites. When either dimension is unreadable the payload now
carries `dimensions_unavailable: true` while width/height stay numeric.

The field is only present when dimensions cannot be read, so existing
consumers that ignore unknown keys are unaffected.
@loonghao
loonghao merged commit b4db6b4 into main Oct 14, 2026
7 checks passed
@loonghao
loonghao deleted the task/document-info-open-document-f587ce819bb1 branch October 14, 2026 18:17
@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
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