# Can't close a document using document.close!

**URL:** <https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549>\
**Category:** Photoshop\
**Tags:** bug, uxp\
**Created:** [December 2, 2022, 5:39pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549 "2022-12-02T17:39:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shwan](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@shwan](https://forums.creativeclouddeveloper.com/u/shwan)\
**Post date:** [December 2, 2022, 5:39pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/1 "2022-12-02T17:39:27Z")

</div>

Hello everyone,

I’m not sure why can’t I make document.close or document.closeWithoutSaving; to work. I think it is a simple enough command. I’m using photoshop 24.1 and working on a plugin. try-catch block did not detect any errors.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![AnthonyK](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@AnthonyK](https://forums.creativeclouddeveloper.com/u/AnthonyK)\
**Post date:** [December 2, 2022, 5:53pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/2 "2022-12-02T17:53:24Z")

</div>

Maybe post your code so we can help you identify the problem.

---

<div class="post-metadata">

**Author:** ![shwan](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@shwan](https://forums.creativeclouddeveloper.com/u/shwan)\
**Post date:** [December 2, 2022, 9:58pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/3 "2022-12-02T21:58:49Z")

</div>

I’m simply trying to open two documents and then closing one of them, I’m doing more stuff, but I tried this code alone, and still, it is not working.

```auto
async function main() {
    const app = require('photoshop').app;
    let imgDocuments = await openDocs();
    await close();
    async function openDocs() {
        try {
            let imgDocuments = [];

            do {
                let entry = await require('uxp').storage.localFileSystem.getFileForOpening()
                const imgDocument = await app.open(entry);
                imgDocuments.push(imgDocument)
            } while (imgDocuments.length < 2)
            return imgDocuments;
        }
        catch (er) { console.log(er) }
    }

    async function close() {
        app.showAlert(app.documents[1].name); //this is for verification
        app.documents[1].closeWithoutSaving;
    }
}
async function generatePhoto() {
    await require("photoshop").core.executeAsModal(main, { "commandName": "Action Commands" });
}

module.exports = {
    generatePhoto
}

```

---

<div class="post-metadata">

**Author:** ![amandah](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/amandah/32/1730_2.png) [@amandah](https://forums.creativeclouddeveloper.com/u/amandah)\
**Post date:** [December 2, 2022, 11:08pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/4 "2022-12-02T23:08:51Z")

</div>

It looks like you aren’t calling it with `()` after the method name

Try `app.documents[1].closeWithoutSaving()`; in the `close` function. Tested on my machine and it closes with no issues. If you still face errors, it may have to do with some other logic you’re using.

---

<div class="post-metadata">

**Author:** ![shwan](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@shwan](https://forums.creativeclouddeveloper.com/u/shwan)\
**Post date:** [December 2, 2022, 11:47pm UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/5 "2022-12-02T23:47:32Z")

</div>

Yes, the () was the issue, That was embarrassing 😳 . However, I can blame the VS code IntelliSense and also I wish the error reporting was more robust.

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [December 3, 2022, 9:24am UTC](https://forums.creativeclouddeveloper.com/t/cant-close-a-document-using-document-close/5549/6 "2022-12-03T09:24:10Z")

</div>

> [@shwan](#):
>
> I wish the error reporting was more robust

In this case there’s nothing to report. There was no error. You were simply not calling a function when you actually wanted to 🙂
